Skip to content

Commit 217b80c

Browse files
P403n1x87MatthieuDartiailh
authored andcommitted
Cythonise all sources
1 parent d98ee89 commit 217b80c

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ coverage.xml
2121
.pytest_cache
2222
.cache
2323
.venv
24+
*.c
25+
*.so

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
[build-system]
34-
requires = ["setuptools>=61.2", "wheel", "setuptools_scm[toml]>=3.4.3"]
34+
requires = ["setuptools>=61.2", "wheel", "setuptools_scm[toml]>=3.4.3", "cython"]
3535
build-backend = "setuptools.build_meta"
3636

3737
[dependency-groups]

setup.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
3+
from setuptools import setup # isort: skip
4+
5+
from pathlib import Path
6+
7+
import Cython.Distutils
8+
from Cython.Build import cythonize # noqa: I100
9+
10+
ROOT = Path(__file__).parent / "src"
11+
12+
13+
# Get all the py files under the src folder
14+
def get_py_files(path):
15+
return [
16+
p.relative_to(ROOT) for p in Path(path).rglob("*.py") if p.name != "__init__.py"
17+
]
18+
19+
20+
def pretend_cython():
21+
return [
22+
Cython.Distutils.Extension(
23+
str(p.with_suffix("")).replace(os.sep, "."),
24+
sources=[str(Path("src") / p)],
25+
language="c",
26+
)
27+
for p in get_py_files(ROOT)
28+
]
29+
30+
31+
setup(
32+
name="bytecode",
33+
setup_requires=["setuptools_scm[toml]>=4", "cython", "cmake>=3.24.2,<3.28"],
34+
ext_modules=cythonize(
35+
pretend_cython(),
36+
force=True,
37+
compiler_directives={
38+
"language_level": "3",
39+
"annotation_typing": False,
40+
},
41+
),
42+
)

0 commit comments

Comments
 (0)