-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
47 lines (39 loc) · 1.37 KB
/
Copy pathsetup.py
File metadata and controls
47 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Optional Cython extensions for StreamMachine.
All project metadata lives in pyproject.toml. This file only exists to
compile the optional accelerators, and only when explicitly requested:
STREAMMACHINE_BUILD_CYTHON=1 pip install "streammachine[cython]"
Without that variable a pure-Python wheel is built and the pure-Python
fallbacks in the package are used at runtime.
"""
import os
from pathlib import Path
from setuptools import Extension, setup
BUILD_CYTHON = os.environ.get("STREAMMACHINE_BUILD_CYTHON", "").lower() in ("1", "true", "yes")
ext_modules = []
if BUILD_CYTHON:
try:
from Cython.Build import cythonize
except ImportError as exc: # pragma: no cover - build-time only
raise SystemExit(
"STREAMMACHINE_BUILD_CYTHON=1 requires Cython: pip install cython"
) from exc
cython_dir = Path("src/streammachine/cython")
ext_modules = cythonize(
[
Extension(
f"streammachine.cython.{pyx.stem}",
[str(pyx)],
extra_compile_args=["-O2"],
)
for pyx in sorted(cython_dir.glob("*.pyx"))
],
compiler_directives={
"language_level": "3",
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"initializedcheck": False,
},
)
setup(ext_modules=ext_modules)