-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
63 lines (60 loc) · 2.39 KB
/
setup.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
from setuptools import find_packages, setup, Extension
import glob
import numpy as np
import sys
# This flag controls whether we build the library with bounds checks and
# other safety measures. Useful when testing where a code breaks down;
# but bad for production performance
debug_library = False
extra_compile_args = []
from Cython.Build import cythonize
import Cython.Compiler.Options
# See https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html
# for a deeper explanation of the choices here
# Cython.Compiler.Options.docstring = False
Cython.Compiler.Options.error_on_uninitialized = True
if not debug_library:
directives = {
"language_level": "3", # We assume Python 3 code
"boundscheck": False, # Do not check array access
"wraparound": False, # a[-1] does not work
"always_allow_keywords": False, # Faster calling conventions
"cdivision": True, # No exception on zero denominator
"initializedcheck": False, # We take care of initializing cdef classes and memory views
"overflowcheck": False,
"binding": False,
}
if sys.platform == "linux":
# We assume GCC or other compilers with compatible command line
extra_compile_args = ["-O3", "-ffast-math"]
else:
# We assume Microsoft Visual C/C++ compiler
extra_compile_args = ["/Ox", "/fp:fast"]
else:
directives = {
"language_level": "3", # We assume Python 3 code
"always_allow_keywords": False, # Faster calling conventions
"boundscheck": True,
"initializedcheck": True,
"wraparound": False,
}
# All Cython files with unix pathnames
cython_files = [s.replace("\\", "/") for s in glob.glob("src/**/*.pyx", recursive=True)]
include_files = [
s.replace("\\", "/") for s in glob.glob("src/**/*.pxi", recursive=True)
]
extension_names = [".".join(f[4:-4].split("/")) for f in cython_files]
print(extension_names)
print(cython_files)
extensions = [
Extension(
name,
[file],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
extra_compile_args=extra_compile_args,
include_dirs=[np.get_include()],
depends=include_files,
)
for name, file in zip(extension_names, cython_files)
]
setup(ext_modules=cythonize(extensions, compiler_directives=directives))