forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py.in
214 lines (191 loc) · 6.94 KB
/
setup.py.in
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from io import open as io_open
import os
import re
import shutil
import subprocess
import sys
import vtk_features
CMAKE_EXE = os.environ.get('CMAKE_EXE', shutil.which('cmake'))
BUILD_DIR = os.path.dirname(os.path.abspath(__file__))
if not CMAKE_EXE or not os.path.exists(CMAKE_EXE):
print('cmake is required to build from source.', file=sys.stderr)
print('Please install cmake or set CMAKE_EXE environment variable.', file=sys.stderr)
sys.exit(1)
class ConfiguredCMakeExtension(Extension):
def __init__(self, name, target=None):
Extension.__init__(self, name, sources=[])
if target is None:
self.target = name
else:
self.target = target
class CMakeBuildExt(build_ext):
def build_extension(self, ext):
if isinstance(ext, ConfiguredCMakeExtension):
output_dir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
subprocess.check_call([CMAKE_EXE, '--build', BUILD_DIR, '--target', ext.target],
cwd=BUILD_DIR)
else:
super().build_extension(ext)
vtk_reqs_path = os.path.join(BUILD_DIR, 'requirements.txt')
with open(vtk_reqs_path, 'r') as fin:
reqs = [
line
for line in [
rawline.strip()
for rawline in fin
]
if not line.startswith('#')
]
vtk_readme_path = os.path.join(BUILD_DIR, 'README.md')
with io_open(vtk_readme_path, encoding='utf-8') as fin:
readme = fin.read()
# Convert all local references to global references to master
readme = re.sub(r'\[(.*?)\]: ((?!https://).*)$',
r'[\1]: https://gitlab.kitware.com/vtk/vtk/-/raw/master/\2',
readme, flags=re.MULTILINE)
readme = re.sub(r'raw/master/(.*).md', r'blob/master/\1.md', readme, flags=re.MULTILINE)
python_code_features = {
'gtk': [],
'numpy': ['numpy>=1.9'],
'qt': [],
'tk': [],
'wx': [],
}
features = python_code_features
features.update(vtk_features.FEATURES)
extra_packages = []
if 'web' in vtk_features.FEATURES:
extra_packages.append('vtkmodules.web')
########################################
# Version computation logic
########################################
# Assume a development version at first.
version_base = '@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.@VTK_BUILD_VERSION@'
version = version_base + '.dev0'
if 'GITLAB_CI' in os.environ:
if 'CI_COMMIT_TAG' in os.environ:
if '.rc' in os.environ['CI_COMMIT_TAG']:
# rc tag. Add this to the version.
rc_bit = os.environ['CI_COMMIT_TAG'].split('.')[-1]
version = version_base + '.' + rc_bit
else:
# Official release, use the version number.
version = version_base
elif 'CI_COMMIT_BRANCH' in os.environ:
# Build on an official branch.
# Check if we're on `master` or the release branch.
if 20200000 < int('@VTK_BUILD_VERSION@'):
# Master, count commits since the last nightly update.
git_log = subprocess.Popen([
'git',
'log',
'--first-parent',
'--pretty=%s',
os.environ['CI_COMMIT_BRANCH'],
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.environ['GIT_CLONE_PATH'],
)
count = 0
for line in git_log.stdout.readlines():
if line == b'VTK Nightly Date Stamp\n':
break
count += 1
else:
# Release branch, count commits since the last tag.
git_log = subprocess.Popen([
'git',
'log',
'--first-parent',
'--pretty=%s',
'v' + version_base + '..'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.environ['GIT_CLONE_PATH'],
)
count = len(git_log.stdout.readlines())
version = version_base + '.dev' + str(count)
elif 'CI_MERGE_REQUEST_ID' in os.environ:
# Build on a merge request.
version = version_base + '.dev0' + '+mr' + \
os.environ['CI_MERGE_REQUEST_ID']
setup(
name='vtk',
version=version,
author='VTK developers',
packages=[
'vtkmodules',
'vtkmodules.gtk',
'vtkmodules.numpy_interface',
'vtkmodules.qt',
'vtkmodules.test',
'vtkmodules.tk',
'vtkmodules.util',
'vtkmodules.wx',
] + extra_packages,
py_modules=[
'vtk',
],
ext_package='vtkmodules',
ext_modules=[
# https://gitlab.kitware.com/cmake/cmake/-/issues/19145
#ConfiguredCMakeExtension('vtkmodules', target='vtkpythonmodules'),
ConfiguredCMakeExtension('vtkCommonCorePython', target='vtkCommonCorePython'),
],
package_data={
'vtkmodules': [
# Linux modules.
'*-linux-gnu.so',
# Unix shared libraries.
'lib*.so*',
# macOS modules.
'*-darwin.so',
# macOS shared libraries.
'.dylibs',
# Windows modules.
'*.pyd',
# Windows shared libraries.
'*.dll',
],
},
cmdclass={
'build_ext': CMakeBuildExt,
},
url='https://vtk.org',
download_url='https://vtk.org/download/',
license='BSD',
classifiers=[
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: C++",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Healthcare Industry",
"Intended Audience :: Science/Research",
"Topic :: Multimedia :: Graphics",
"Topic :: Multimedia :: Graphics :: 3D Modeling",
"Topic :: Multimedia :: Graphics :: 3D Rendering",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Software Development :: Libraries",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS"
],
description='VTK is an open-source toolkit for 3D computer graphics, image processing, and visualization',
long_description=readme,
long_description_content_type='text/markdown',
install_requires=reqs,
extras_require=features,
include_package_data=True,
zip_safe=False,
)