-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
190 lines (150 loc) · 6.18 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import re
import sys
import platform
import subprocess
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion
from setuptools.command.develop import develop
from setuptools.command.install import install
from setuptools.command.sdist import sdist
from setuptools.command.build_py import build_py
from setuptools import setup, find_packages
from subprocess import check_call, check_output
with open('README.rst') as f:
readme = f.read()
""" Specific versions of submodules to use. """
submoduleVersions = {
'clipper2': 'Clipper2_1.3.0',
'pybind11': 'v2.11',
'eigen': '3.4'
}
class CMakeExtension(Extension):
def __init__(self, name, modName, sourcedir=''):
Extension.__init__(self, name, sources=[], language='c++')
self.modName = modName
self.sourcedir = os.path.abspath(sourcedir)
def gitcmd_update_submodules():
"""
Check if the package is being deployed as a git repository. If so, recursively update all dependencies.
"""
if os.path.exists('.git'):
check_call(['git', 'submodule', 'update', '--init', '--recursive'])
# set all versions as required
curPath = os.path.abspath('.')
for k, v in submoduleVersions.items():
modPath = os.path.abspath('{:s}/external/{:s}'.format(curPath, k))
import subprocess
process = subprocess.Popen(['git', 'checkout', v], cwd=modPath)
check_call(['git', 'submodule', 'status'])
return True
return False
class gitcmd_develop(develop):
"""
Specialized packaging class that runs `git submodule update --init --recursive`
as part of the update/install procedure.
"""
def run(self):
gitcmd_update_submodules()
develop.run(self)
class gitcmd_install(install):
"""
Specialized packaging class that runs `git submodule update --init --recursive`
as part of the update/install procedure.
"""
def run(self):
gitcmd_update_submodules()
install.run(self)
class gitcmd_sdist(sdist):
"""
Specialized packaging class that runs git submodule update --init --recursive
as part of the update/install procedure;.
"""
def run(self):
gitcmd_update_submodules()
sdist.run(self)
class CMakeBuild(build_ext):
def run(self):
# Update the submodules to the correct version
gitcmd_update_submodules()
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
if platform.system() == "Windows":
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1))
if cmake_version < '3.12.0':
raise RuntimeError("CMake >= 3.12.0 is required on Windows")
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
"""
Builds the following CMake extension within the project tree
:param ext: CMake Extension to build
"""
print('ext_full_path', self.get_ext_fullpath(ext.name))
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
# required for auto-detection of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
extdir += os.path.sep
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DBUILD_PYTHON=ON']
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
if platform.system() == "Windows":
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
if sys.maxsize > 2**32:
cmake_args += ['-A', 'x64']
build_args += ['--', '/m']
else:
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
build_args += ['--', '-j4']
cmake_args += ['-DCMAKE_INSTALL_PREFIX=' + '.']
env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
self.distribution.get_version())
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.', '--target', ext.modName] + build_args, cwd=self.build_temp)
setup(
name='pyclipr',
version='0.1.7',
author='Luke Parry',
author_email='[email protected]',
url='https://github.com/drlukeparry/pyclipr',
long_description=readme,
long_description_content_type = 'text/x-rst',
description='Python library for polygon clipping and offsetting based on Clipper2.',
ext_modules=[CMakeExtension('pyclipr.pyclipr', 'pyclipr')],
cmdclass= {
'build_ext': CMakeBuild,
'develop': gitcmd_develop,
'sdist': gitcmd_sdist,
},
packages = ['pyclipr'],
package_dir={'': 'python'},
keywords=['polygon clipping', 'polygon offsetting', 'libClipper', 'Clipper2', 'polygon boolean', 'polygon', 'line clipping', 'clipper'],
# tell setuptools that all packages will be under the 'src' directory
# and nowhere else
zip_safe=False,
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Natural Language :: English',
'Topic :: Scientific/Engineering'],
license="",
project_urls = {
'Documentation': 'https://github.com/drylukeparry/pyclipr',
'Source': 'https://github.com/drylukeparry/pyclipr',
'Tracker': 'https://github.com/drlukeparry/pyclipr/issues'
}
)