forked from TUW-GEO/pytesmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
106 lines (89 loc) · 3.31 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
"""
Setup file for pytesmo.
Use setup.cfg to configure your project.
This file was generated with PyScaffold 4.5.
PyScaffold helps you to put up the scaffold of your new Python project.
Learn more under: https://pyscaffold.org/
"""
from setuptools import setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.sdist import sdist as _sdist
from setuptools.extension import Extension
import numpy
# list of C/Cython extensions
def get_ext_modules(ext):
return [
Extension(
"pytesmo.time_series.filters",
["src/pytesmo/time_series/filters" + ext],
include_dirs=[numpy.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
Extension(
"pytesmo.metrics._fast",
["src/pytesmo/metrics/_fast" + ext],
include_dirs=[numpy.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
Extension(
"pytesmo.metrics._fast_pairwise",
["src/pytesmo/metrics/_fast_pairwise" + ext],
include_dirs=[numpy.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
]
# defining a custom cythonize function that sets all the options we want and
# that can be reused for the different options
def cythonize_extensions():
from Cython.Build import cythonize
cythonized_modules = cythonize(
get_ext_modules(".pyx"),
compiler_directives={
"embedsignature": True,
"language_level": 3,
# "warn.undeclared": True,
# "warn.maybe_unitialized": True,
"warn.unused": True,
# "warn.unused_arg": True,
# "warn.unused_result": True,
},
# include_path=[numpy.get_include()],
)
return cythonized_modules
class CythonizeMixin(object):
user_options = [
("cythonize", None, "recreate the c extensions with cython")
]
def initialize_options(self):
super().initialize_options()
self.cythonize = False
def run(self):
if self.cythonize:
self.distribution.ext_modules = cythonize_extensions()
super().run()
class sdist(CythonizeMixin, _sdist):
user_options = getattr(_sdist, 'user_options', [])\
+ CythonizeMixin.user_options
class build_ext(CythonizeMixin, _build_ext):
user_options = getattr(_build_ext, 'user_options', [])\
+ CythonizeMixin.user_options
if __name__ == "__main__":
# to create .c files run `python setup.py build_ext --cythonize`
try:
cmdclass = {}
cmdclass["sdist"] = sdist
cmdclass["build_ext"] = build_ext
setup(
cmdclass=cmdclass,
# at this point the C modules have already been generated if necessary # noqa: E501
ext_modules=get_ext_modules(".c"),
use_scm_version={"version_scheme": "no-guess-dev"}
)
except: # noqa
print(
"\n\nAn error occurred while building the project, "
"please ensure you have the most updated version of setuptools, "
"setuptools_scm and wheel with:\n"
" pip install -U setuptools setuptools_scm wheel\n\n"
)
raise