-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsetup.py
More file actions
52 lines (41 loc) · 1.46 KB
/
setup.py
File metadata and controls
52 lines (41 loc) · 1.46 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
48
49
50
51
52
"""Build C extensions for sendspin."""
import os
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
_REQUIRE_C_EXT = os.environ.get("SENDSPIN_REQUIRE_C_EXT") == "1"
class OptionalBuildExt(build_ext):
"""A build_ext that treats C extensions as optional.
If compilation fails (e.g. missing compiler or headers), the error is
reported but does not abort the build, allowing the numpy fallback to be
used at runtime.
Set SENDSPIN_REQUIRE_C_EXT=1 to make compilation failures fatal (used in
CI to ensure wheels always include the C extension).
"""
def run(self) -> None:
try:
super().run()
except Exception as exc:
if _REQUIRE_C_EXT:
raise
print(
"WARNING: Building C extensions for sendspin failed; "
"falling back to numpy implementation. "
f"Error: {exc}",
)
def build_extension(self, ext: Extension) -> None:
try:
super().build_extension(ext)
except Exception as exc:
if _REQUIRE_C_EXT:
raise
print(
f"WARNING: Failed to build extension {ext.name!r}; "
"continuing without it. "
f"Error: {exc}",
)
setup(
ext_modules=[
Extension("sendspin._volume", sources=["sendspin/_volume.c"]),
],
cmdclass={"build_ext": OptionalBuildExt},
)