-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
139 lines (120 loc) · 3.83 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
import os
from setuptools import setup
from setuptools.extension import Extension
BUILD_ARGS = {
"default": {
"posix": {
"extra_compile_args": ["-O2"],
"extra_link_args": [],
"libraries": [],
},
"nt": {
"extra_compile_args": ["/O2"],
"extra_link_args": [],
"libraries": [],
},
},
"debug": {
"posix": {
"extra_compile_args": ["-O0", "-g"],
"extra_link_args": [],
"libraries": [],
},
"nt": {
"extra_compile_args": ["/Od"],
"extra_link_args": [],
"libraries": [],
},
},
"optimize": {
"posix": {
"extra_compile_args": [
"-O3",
"-march=native",
"-ffast-math",
],
"extra_link_args": [],
"libraries": [],
},
"nt": {
"extra_compile_args": [
"/Ox",
"/fp:fast",
],
"extra_link_args": [],
"libraries": [],
},
},
}
def make_extension(name, extension, defaults):
import numpy
include_dirs = extension.get("include_dirs", [])
include_dirs.append(numpy.get_include())
libraries = extension.get("libraries", [])
libraries.extend(defaults["libraries"])
extra_compile_args = extension.get("extra_compile_args", [])
extra_compile_args.extend(defaults["extra_compile_args"])
extra_link_args = extension.get("extra_link_args", [])
extra_link_args.extend(defaults["extra_compile_args"])
return Extension(
name,
sources=extension["sources"],
include_dirs=include_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
if __name__ == "__main__":
from Cython.Build import cythonize
build_type = os.getenv("WILDBOAR_BUILD", "default")
build_nthreads = int(os.getenv("WILDBOAR_BUILD_NTHREADS", "1"))
build_args = BUILD_ARGS.get(build_type, {}).get(os.name, None)
if build_args is None:
raise RuntimeError(f"{build_type} is not a valid build type")
external_extra_compile_args = os.getenv("WILDBOAR_EXTRA_COMPILE_ARGS")
if external_extra_compile_args is not None:
import re
build_args["extra_compile_args"].extend(
re.split(r"\s+", external_extra_compile_args)
)
if os.name == "posix":
build_args["libraries"].append("m")
extensions = {
"wildboar.distance.*": {
"sources": ["src/wildboar/distance/*.pyx"],
},
"wildboar.tree.*": {
"sources": ["src/wildboar/tree/*.pyx"],
},
"wildboar.transform.*": {
"sources": ["src/wildboar/transform/*.pyx"],
},
"wildboar.transform.catch22._catch22": {
"sources": [
"src/wildboar/transform/catch22/_catch22.pyx",
"src/wildboar/transform/catch22/src/catch22.c",
],
"include_dirs": ["src/wildboar/transform/catch22/src/"],
},
"wildboar.utils._fft._pocketfft": {
"sources": [
"src/wildboar/utils/_fft/_pocketfft.pyx",
"src/wildboar/utils/_fft/src/pocketfft.c",
],
"include_dirs": ["src/wildboar/utils/_fft/src/"],
},
"wildboar.utils.*": {"sources": ["src/wildboar/utils/*.pyx"]},
}
ext_modules = [
make_extension(name, options, build_args)
for name, options in extensions.items()
]
setup(
ext_modules=cythonize(
ext_modules,
nthreads=build_nthreads,
annotate=build_type == "debug",
)
)