generated from BrianPugh/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
104 lines (89 loc) · 3.06 KB
/
build.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import shutil
from pathlib import Path
allowed_to_fail = os.environ.get("CIBUILDWHEEL", "0") != "1"
profile = os.environ.get("TAMP_PROFILE", "0") == "1"
def build_cython_extensions():
import Cython.Compiler.Options
from Cython.Build import build_ext, cythonize
from Cython.Compiler.Options import get_directive_defaults
from setuptools import Extension
from setuptools.dist import Distribution
Cython.Compiler.Options.annotate = True
define_macros = []
if profile:
print("Setting profiling configuration.")
directive_defaults = get_directive_defaults()
directive_defaults["linetrace"] = True
directive_defaults["binding"] = True
define_macros.append(("CYTHON_TRACE", "1"))
if os.name == "nt": # Windows
extra_compile_args = [
"/O2",
]
else: # UNIX-based systems
extra_compile_args = [
"-O3",
"-Werror",
"-Wno-unreachable-code-fallthrough",
"-Wno-deprecated-declarations",
"-Wno-parentheses-equality",
"-Wno-unreachable-code", # TODO: This should no longer be necessary with Cython>=3.0.3
# https://github.com/cython/cython/issues/5681
]
include_dirs = ["tamp/_c_src/", "tamp/"]
extensions = [
Extension(
"tamp._c_compressor",
[
"tamp/_c_src/tamp/common.c",
"tamp/_c_src/tamp/compressor.c",
"tamp/_c_compressor.pyx",
],
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c",
define_macros=define_macros,
),
Extension(
"tamp._c_decompressor",
[
"tamp/_c_src/tamp/common.c",
"tamp/_c_src/tamp/decompressor.c",
"tamp/_c_decompressor.pyx",
],
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c",
define_macros=define_macros,
),
Extension(
"tamp._c_common",
[
"tamp/_c_common.pyx",
],
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c",
define_macros=define_macros,
),
]
include_dirs = set()
for extension in extensions:
include_dirs.update(extension.include_dirs)
include_dirs = list(include_dirs)
ext_modules = cythonize(extensions, include_path=include_dirs, language_level=3, annotate=True)
dist = Distribution({"ext_modules": ext_modules})
cmd = build_ext(dist)
cmd.ensure_finalized()
cmd.run()
for output in cmd.get_outputs():
output = Path(output)
relative_extension = output.relative_to(cmd.build_lib)
shutil.copyfile(output, relative_extension)
if os.environ.get("TAMP_BUILD_C_EXTENSIONS", "1") == "1":
try:
build_cython_extensions()
except Exception:
if not allowed_to_fail:
raise