-
Notifications
You must be signed in to change notification settings - Fork 177
/
build.py
55 lines (46 loc) · 1.61 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
import os
import shutil
import sys
from distutils.command.build_ext import build_ext
from distutils.core import Distribution, Extension
from Cython.Build import cythonize
import numpy as np
compile_args = ["-O3"]
link_args = []
include_dirs = [np.get_include()]
libraries = ["m"]
def build():
debug_mode_on = '1' if 'debug_mode_on' in os.environ else '0'
extensions = [
Extension(
"*",
["zigzag/*.pyx"],
extra_compile_args=compile_args,
extra_link_args=link_args,
include_dirs=include_dirs,
libraries=libraries if os.name != 'nt' else [],
define_macros=[('CYTHON_TRACE', debug_mode_on),
('CYTHON_TRACE_NOGIL', debug_mode_on),
('CYTHON_BINDING', debug_mode_on),
('CYTHON_FAST_PYCCALL', '1')],
)
]
ext_modules = cythonize(
extensions,
include_path=include_dirs,
compiler_directives={"binding": True, "language_level": sys.version_info.major},
)
distribution = Distribution({"name": "extended", "ext_modules": ext_modules})
distribution.package_dir = "extended"
cmd = build_ext(distribution)
cmd.ensure_finalized()
cmd.run()
# Copy built extensions back to the project
for output in cmd.get_outputs():
relative_extension = os.path.relpath(output, cmd.build_lib)
shutil.copyfile(output, relative_extension)
mode = os.stat(relative_extension).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(relative_extension, mode)
if __name__ == "__main__":
build()