forked from sogno-platform/dpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
70 lines (56 loc) · 2.29 KB
/
setup.py
File metadata and controls
70 lines (56 loc) · 2.29 KB
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
import os
import sys
import platform
import subprocess
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name):
Extension.__init__(self, name, sources=[])
class CMakeBuild(build_ext):
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cfg = "Debug" if self.debug else "Release"
print("building CMake extension in %s configuration" % cfg)
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG={extdir}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # Not used on MSVC, but no harm
"-DCMAKE_POLICY_VERSION_MINIMUM=3.5",
]
if platform.system() == "Windows":
cmake_args += ["-A", "x64"]
build_args = ["--", "/m"]
else:
if self.parallel:
build_args = ["--", "-j" + str(self.parallel)]
else:
build_args = ["--", "-j4"]
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
env = os.environ.copy()
if env.get("CMAKE_OPTS"):
cmake_args += env.get("CMAKE_OPTS").split(" ")
# CMakeLists.txt is in the same directory as this setup.py file
sourcedir = os.path.abspath(os.path.dirname(__file__))
print(" ".join(["cmake", sourcedir] + cmake_args))
subprocess.check_call(
["cmake", sourcedir] + cmake_args, cwd=self.build_temp, env=env
)
print(" ".join(["cmake", "--build", ".", "--target", "dpsimpy"] + build_args))
subprocess.check_call(
["cmake", "--build", ".", "--target", "dpsimpy"] + build_args,
cwd=self.build_temp,
)
setup(
packages=find_packages("python/src"),
package_dir={"dpsim": "python/src/dpsim"},
python_requires=">=3.8",
setup_requires=["pytest-runner", "wheel"],
tests_require=["pytest", "pyyaml", "nbformat", "nbconvert"],
ext_modules=[CMakeExtension("dpsimpy")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
)