-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsetup.py
68 lines (54 loc) · 1.8 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
import os
import sys
import numpy as np
from Cython import Tempita as tempita
from Cython.Build import cythonize
from setuptools import setup
from setuptools.extension import Extension
import versioneer
compile_args = dict(
library_dirs=[
os.path.abspath(os.path.join(np.get_include(), "..", "lib")),
],
include_dirs=[np.get_include(), "crick/klib"],
libraries=["npymath"],
)
if "--debug" in sys.argv:
sys.argv.remove("--debug")
compile_args["undef_macros"] = ["NDEBUG"]
compile_args["extra_compile_args"] = ["-O0"]
def generate_code(templates):
"""Generate code from template files"""
for template in templates:
# template extension must be .in
assert template.endswith(".in")
outfile = template[:-3]
if os.path.exists(outfile) and (
not os.path.exists(template)
or os.stat(template).st_mtime < os.stat(outfile).st_mtime
):
# If output is present but template isn't, or if template is not
# updated, then no need to generate
continue
with open(template) as f:
tmpl = f.read()
output = tempita.sub(tmpl)
with open(outfile, "w") as f:
f.write(output)
templates = ["crick/space_saving_stubs.c.in"]
generate_code(templates)
extensions = [
Extension("crick.tdigest", ["crick/tdigest.pyx"], **compile_args),
Extension("crick.space_saving", ["crick/space_saving.pyx"], **compile_args),
Extension("crick.stats", ["crick/stats.pyx"], **compile_args),
Extension(
"crick.numpy_version",
["crick/numpy_version.pyx"],
extra_compile_args=[f'-DNUMPY_VERSION="{np.__version__}"'],
),
]
setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
ext_modules=cythonize(extensions),
)