-
Notifications
You must be signed in to change notification settings - Fork 110
/
setup.py
145 lines (132 loc) · 5.35 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
import os
import re
import shutil
import setuptools
import subprocess
def run_meson_build():
# check if ipopt dir is specified
ipopt_dir_opt = ""
if "IPOPT_DIR" in os.environ:
ipopt_dir = os.environ["IPOPT_DIR"]
ipopt_dir_opt = f"-Dipopt_dir={ipopt_dir}"
prefix = os.path.join(os.getcwd(), staging_dir)
purelibdir = "."
# check if meson extra args are specified
meson_args = ""
if "MESON_ARGS" in os.environ:
meson_args = os.environ["MESON_ARGS"]
# check to make sure ipopt dir isnt specified twice
if "-Dipopt_dir" in meson_args and ipopt_dir_opt != "":
raise RuntimeError("IPOPT_DIR environment variable is set and '-Dipopt_dir' in MESON_ARGS")
# configure
meson_path = shutil.which("meson")
meson_call = (
f"{meson_path} setup {staging_dir} --prefix={prefix} "
+ f"-Dpython.purelibdir={purelibdir} -Dpython.platlibdir={purelibdir} {ipopt_dir_opt} {meson_args}"
)
sysargs = meson_call.split(" ")
sysargs = [arg for arg in sysargs if arg != ""]
p1 = subprocess.run(sysargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
setup_log = os.path.join(staging_dir, "setup.log")
with open(setup_log, "wb") as f:
f.write(p1.stdout)
if p1.returncode != 0:
with open(setup_log, "r") as f:
print(f.read())
raise OSError(sysargs, f"The meson setup command failed! Check the log at {setup_log} for more information.")
# build
meson_call = f"{meson_path} compile -C {staging_dir}"
sysargs = meson_call.split(" ")
p2 = subprocess.run(sysargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
compile_log = os.path.join(staging_dir, "compile.log")
with open(compile_log, "wb") as f:
f.write(p2.stdout)
if p2.returncode != 0:
with open(compile_log, "r") as f:
print(f.read())
raise OSError(
sysargs, f"The meson compile command failed! Check the log at {compile_log} for more information."
)
def copy_shared_libraries():
build_path = os.path.join(staging_dir, "pyoptsparse")
for root, _dirs, files in os.walk(build_path):
for file in files:
# move pyoptsparse to just under staging_dir
if file.endswith((".so", ".lib", ".pyd", ".pdb", ".dylib")):
if ".so.p" in root or ".pyd.p" in root: # excludes intermediate object files
continue
file_path = os.path.join(root, file)
new_path = str(file_path)
match = re.search(staging_dir, new_path)
new_path = new_path[match.span()[1] + 1 :]
print(f"Copying build file {file_path} -> {new_path}")
shutil.copy(file_path, new_path)
if __name__ == "__main__":
# This is where the meson build system will install to, it is then
# used as the sources for setuptools
staging_dir = "meson_build"
# this keeps the meson build system from running more than once
if "dist" not in str(os.path.abspath(__file__)) and not os.path.isdir(staging_dir):
cwd = os.getcwd()
run_meson_build()
os.chdir(cwd)
copy_shared_libraries()
docs_require = ""
req_txt = os.path.join("doc", "requirements.txt")
if os.path.isfile(req_txt):
with open(req_txt) as f:
docs_require = f.read().splitlines()
init_file = os.path.join("pyoptsparse", "__init__.py")
__version__ = re.findall(
r"""__version__ = ["']+([0-9\.]*)["']+""",
open(init_file).read(),
)[0]
setuptools.setup(
name="pyoptsparse",
version=__version__,
description="Python package for formulating and solving nonlinear constrained optimization problems",
long_description="pyOptSparse is a Python package for formulating and solving nonlinear constrained optimization problems",
platforms=["Linux"],
keywords="optimization",
install_requires=[
"packaging",
"sqlitedict>=1.6",
"numpy>=1.21,<2",
"scipy>=1.7",
"mdolab-baseclasses>=1.3.1",
],
extras_require={
"optview": [
"dash",
"plotly",
"matplotlib",
],
"docs": docs_require,
"testing": ["testflo>=1.4.5", "parameterized"],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
"Topic :: Education",
],
package_dir={"": "."},
packages=setuptools.find_packages(where="."),
package_data={
"": ["*.so", "*.lib", "*.pyd", "*.pdb", "*.dylib", "assets/*", "LICENSE"],
},
python_requires=">=3.9",
entry_points={
"gui_scripts": [
"optview = pyoptsparse.postprocessing.OptView:main",
"optview_dash = pyoptsparse.postprocessing.OptView_dash:main",
]
},
)