-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
162 lines (121 loc) · 4.06 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
import io
import os
import subprocess
import shutil
from setuptools import setup, find_packages, Command
from packaging import version
NAME = "jigsawpy"
DESCRIPTION = \
"Python interface for the JIGSAW meshing library."
AUTHOR = "Darren Engwirda"
AUTHOR_EMAIL = "[email protected]"
URL = "https://github.com/dengwirda/"
VERSION = "1.0.0"
REQUIRES_PYTHON = ">=3.6.0"
KEYWORDS = "Mesh-generation Delaunay Voronoi"
REQUIRED = [
"numpy", "scipy"
]
CLASSIFY = [
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
"Intended Audience :: Science/Research",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: C++",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Visualization"
]
HERE = os.path.abspath(os.path.dirname(__file__))
try:
with io.open(os.path.join(
HERE, "README.md"), encoding="utf-8") as f:
LONG_DESCRIPTION = "\n" + f.read()
except FileNotFoundError:
LONG_DESCRIPTION = DESCRIPTION
def get_cmake_version():
try:
out = subprocess.check_output(
["cmake", "--version"]).decode("utf-8")
sln = out.splitlines()[0]
ver = sln.split()[2]
return ver
except:
print("cmake not found!")
class build_external(Command):
description = "build external JIGSAW dependencies"
user_options = []
def initialize_options(self): pass
def finalize_options(self): pass
def run(self):
"""
The actual cmake-based build steps for JIGSAW
"""
if (self.dry_run): return
cwd_pointer = os.getcwd()
try:
self.announce("cmake config.", level=3)
source_path = os.path.join(
HERE, "external", "jigsaw")
builds_path = \
os.path.join(source_path, "tmp")
os.makedirs(builds_path, exist_ok=True)
exesrc_path = \
os.path.join(source_path, "bin")
libsrc_path = \
os.path.join(source_path, "lib")
exedst_path = os.path.join(
HERE, "jigsawpy", "_bin")
libdst_path = os.path.join(
HERE, "jigsawpy", "_lib")
shutil.rmtree(
exedst_path, ignore_errors=True)
shutil.rmtree(
libdst_path, ignore_errors=True)
os.chdir(builds_path)
config_call = [
"cmake",
"..", "-DCMAKE_BUILD_TYPE=Release"]
subprocess.run(config_call, check=True)
self.announce("cmake complie", level=3)
ver = get_cmake_version()
if version.parse(ver) < version.parse("3.12"):
compilecall = [
"cmake", "--build", ".",
"--config", "Release",
"--target", "install"
]
else:
compilecall = [
"cmake", "--build", ".",
"--config", "Release",
"--target", "install",
"--parallel", "4"
]
subprocess.run(compilecall, check=True)
self.announce("cmake cleanup", level=3)
shutil.copytree(exesrc_path, exedst_path)
shutil.copytree(libsrc_path, libdst_path)
finally:
os.chdir(cwd_pointer)
shutil.rmtree(builds_path)
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
license="custom",
author=AUTHOR,
author_email=AUTHOR_EMAIL,
python_requires=REQUIRES_PYTHON,
keywords=KEYWORDS,
url=URL,
packages=find_packages(exclude=["tests",]),
cmdclass={"build_external": build_external},
package_data={"jigsawpy": ["_bin/*", "_lib/*"]},
install_requires=REQUIRED,
classifiers=CLASSIFY
)