代码拉取完成,页面将自动刷新
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=[
"sqlitedict>=1.6",
"numpy>=1.16",
"scipy>1.2",
"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.7",
entry_points={
"gui_scripts": [
"optview = pyoptsparse.postprocessing.OptView:main",
"optview_dash = pyoptsparse.postprocessing.OptView_dash:main",
]
},
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。