-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
127 lines (103 loc) · 4.17 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
import os
import platform
import setuptools
import sys
import subprocess
import shutil
from pathlib import Path
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
from distutils.util import get_platform
class CMakeExtension(Extension):
def __init__(self, name, sourcedir = ""):
Extension.__init__(self, name, sources = [])
self.sourcedir = Path(sourcedir).absolute()
class CMakeBuild(build_ext):
"""
This class is built upon https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/build_extension.py and https://github.com/pybind/cmake_example/blob/master/setup.py
"""
user_options = build_ext.user_options + [
("define=", "D", "Define variables for CMake")
]
def initialize_options(self):
super().initialize_options()
self.define = None
def finalize_options(self):
# Parse the custom CMake options and store them in a new attribute
defines = [] if self.define is None else self.define.split(";")
self.cmake_defines = [f"-D{define}" for define in defines]
super().finalize_options()
def build_extension(self, ext: CMakeExtension):
extdir = str(Path(self.get_ext_fullpath(ext.name)).parent.absolute())
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
configure_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
]
if "CMAKE_ARGS" in os.environ:
configure_args += os.environ["CMAKE_ARGS"].split(" ")
configure_args += self.cmake_defines
build_args = []
# Add more platform dependent options
if platform.system() == "Darwin":
pass
elif platform.system() == "Linux":
pass
elif platform.system() == "Windows":
pass
else:
raise RuntimeError(f"Unsupported '{platform.system()}' platform")
if not Path(self.build_temp).exists():
os.makedirs(self.build_temp)
subprocess.check_call(
["cmake", str(ext.sourcedir)] + configure_args, cwd = self.build_temp
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd = self.build_temp
)
with open("polyval2d_mp/_version.py") as f:
version = f.readlines()[-1].split()[-1].strip("\"'")
requirements = [
]
info = {
"name": "polyval2d-high-precision",
"version": version,
"maintainer": "Chae-Yeun Park",
"maintainer_email": "[email protected]",
"url": "https://github.com/XanaduAI/polyval2d-high-precision",
"license": "GNU Lesser General Public License v2.1",
"packages": find_packages(where="."),
"package_data": {},
"entry_points": {
},
"description": "C++ helper tool for efficient computation of poly2val",
"long_description": open("README.rst").read(),
"long_description_content_type": "text/x-rst",
"provides": ["polyval2d_mp"],
"install_requires": requirements,
"ext_modules": [CMakeExtension("_polyval2d_binding")],
"cmdclass": {"build_ext": CMakeBuild},
"ext_package": "polyval2d_mp"
}
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Natural Language :: English",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Physics",
]
setup(classifiers=classifiers, **(info))