-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
232 lines (200 loc) · 6.97 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import os
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
def setup_package():
compiler_directives = {
"language_level": 3,
"embedsignature": True,
}
define_macros = []
compile_time_env = {}
annotate = False
class new_build_ext(_build_ext):
def finalize_options(self):
# Defer the import of Cython and NumPy until after setup_requires
from Cython.Build.Dependencies import cythonize
import numpy
self.distribution.ext_modules[:] = cythonize(
self.distribution.ext_modules,
compiler_directives=compiler_directives,
compile_time_env=compile_time_env,
annotate=annotate,
)
if not self.include_dirs:
self.include_dirs = []
elif isinstance(self.include_dirs, str):
self.include_dirs = [self.include_dirs]
self.include_dirs.append(numpy.get_include())
super().finalize_options()
# Extra optional dependencies
docs_extras = ["sphinx", "sphinx_rtd_theme", "numpydoc", "matplotlib"]
notebook_extras = ["ipython", "jinja2", "matplotlib"]
opt_extras = ["platypus-opt", "pygmo"]
test_extras = ["pytest"] + notebook_extras + opt_extras
dev_extras = docs_extras + test_extras
metadata = dict(
name="pywr",
description="Python Water Resource model",
long_description=long_description(),
long_description_content_type="text/x-rst",
author="Joshua Arnott",
author_email="[email protected]",
url="https://github.com/pywr/pywr",
setup_requires=[
"setuptools>=62",
"setuptools_scm[toml]>=8.0",
"cython>=3",
"numpy",
],
install_requires=[
"pandas",
"networkx",
"numpy",
"scipy",
"tables",
"openpyxl",
"packaging",
],
extras_require={
"docs": docs_extras,
"test": test_extras,
"dev": dev_extras,
"optimisation": opt_extras,
"notebook": notebook_extras,
},
cmdclass={"build_ext": new_build_ext},
packages=[
"pywr",
"pywr.solvers",
"pywr.domains",
"pywr.parameters",
"pywr.recorders",
"pywr.notebook",
"pywr.optimisation",
"pywr.utils",
],
package_data=package_data(),
use_scm_version=True,
)
metadata["ext_modules"] = ext_modules = [
Extension("pywr._core", ["pywr/_core.pyx"]),
Extension("pywr._model", ["pywr/_model.pyx"]),
Extension("pywr._component", ["pywr/_component.pyx"]),
Extension("pywr.parameters._parameters", ["pywr/parameters/_parameters.pyx"]),
Extension("pywr.parameters._polynomial", ["pywr/parameters/_polynomial.pyx"]),
Extension("pywr.parameters._thresholds", ["pywr/parameters/_thresholds.pyx"]),
Extension(
"pywr.parameters._control_curves", ["pywr/parameters/_control_curves.pyx"]
),
Extension("pywr.parameters._hydropower", ["pywr/parameters/_hydropower.pyx"]),
Extension(
"pywr.parameters._activation_functions",
["pywr/parameters/_activation_functions.pyx"],
),
Extension("pywr.recorders._recorders", ["pywr/recorders/_recorders.pyx"]),
Extension("pywr.recorders._thresholds", ["pywr/recorders/_thresholds.pyx"]),
Extension("pywr.recorders._hydropower", ["pywr/recorders/_hydropower.pyx"]),
]
config = parse_optional_arguments()
if config["glpk"]:
ext_modules.append(
Extension(
"pywr.solvers.cython_glpk",
["pywr/solvers/cython_glpk.pyx"],
libraries=["glpk"],
)
)
if config["lpsolve"]:
if os.name == "nt":
lpsolve_macros = define_macros + [("WIN32", 1)]
else:
lpsolve_macros = define_macros
ext_modules.append(
Extension(
"pywr.solvers.cython_lpsolve",
["pywr/solvers/cython_lpsolve.pyx"],
libraries=["lpsolve55"],
define_macros=lpsolve_macros,
)
)
annotate = config["annotate"]
if config["profile"]:
compiler_directives["profile"] = True
if config["trace"]:
compiler_directives["linetrace"] = True
define_macros.extend(
[
("CYTHON_TRACE", "1"),
("CYTHON_TRACE_NOGIL", "1"),
]
)
setup(**metadata)
def long_description():
with open("README.rst") as f:
return f.read()
def package_data():
pkg_data = {
"pywr.notebook": ["*.js", "*.css", "*.html"],
"pywr": ["*.pxd"],
"pywr.parameters": ["*.pxd"],
"pywr.recorders": ["*.pxd"],
"pywr.solvers": ["*.pxd"],
}
if os.environ.get("PACKAGE_DATA", "false").lower() == "true":
pkg_data["pywr"].extend([".libs/*", ".libs/licenses/*"])
return pkg_data
def parse_optional_arguments():
config = {
"glpk": True,
"lpsolve": True,
"annotate": False,
"profile": False,
"trace": False,
}
if "--with-glpk" in sys.argv:
config["glpk"] = True
sys.argv.remove("--with-glpk")
elif "PYWR_BUILD_GLPK" in os.environ:
config["glpk"] = os.environ["PYWR_BUILD_GLPK"].lower() in (
"true",
"1",
)
elif "--without-glpk" in sys.argv:
config["glpk"] = False
sys.argv.remove("--without-glpk")
if "--with-lpsolve" in sys.argv:
config["lpsolve"] = True
sys.argv.remove("--with-lpsolve")
elif "PYWR_BUILD_LPSOLVE" in os.environ:
config["lpsolve"] = os.environ["PYWR_BUILD_LPSOLVE"].lower() in (
"true",
"1",
)
elif "--without-lpsolve" in sys.argv:
config["lpsolve"] = False
sys.argv.remove("--without-lpsolve")
if "--annotate" in sys.argv:
config["annotate"] = True
sys.argv.remove("--annotate")
if "--enable-profiling" in sys.argv:
config["profile"] = True
sys.argv.remove("--enable-profiling")
if "--enable-trace" in sys.argv:
config["trace"] = True
sys.argv.remove("--enable-trace")
elif "PYWR_BUILD_TRACE" in os.environ:
config["trace"] = os.environ["PYWR_BUILD_TRACE"].lower() in (
"true",
"1",
)
if "--enable-debug" in sys.argv:
import warnings
warnings.warn(
"--enable-debug has been deprecated. Its functionality is now enabled by default. To disable"
"GLPK error handling please use the `use_unsafe_api` option in the GLPK solvers."
)
sys.argv.remove("--enable-debug")
return config
if __name__ == "__main__":
setup_package()