-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathbuild_wheel.py
More file actions
199 lines (171 loc) · 6.9 KB
/
Copy pathbuild_wheel.py
File metadata and controls
199 lines (171 loc) · 6.9 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
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
import functools
import os
import platform
import shutil
import subprocess
import sys
import re
from argparse import ArgumentParser
from string import Template
from build_constants import *
import create_stubs
def install_packages():
create_stubs.install_packages()
packages = [
"build",
"setuptools",
"wheel",
"numpy", # Because the modules we're building depend on it.
]
platform_specific_packages = {
'Darwin': [
"delocate==0.10.7",
],
'Linux': [
"auditwheel",
],
'Windows': [
"delvewheel",
],
}
packages += platform_specific_packages[SYSTEM]
subprocess.check_call(
["pip", "install", "--upgrade", "pip"]
)
subprocess.check_call(
["pip", "install", "--upgrade", *packages]
)
def setup_workspace(version, modules, plat_name):
if WHEEL_ROOT_DIR.exists():
shutil.rmtree(WHEEL_ROOT_DIR)
WHEEL_SRC_DIR.mkdir(parents=True)
create_stubs.setup_workspace(modules, False)
print("Copying LICENSE and readme.md")
shutil.copy(SOURCE_DIR / "LICENSE", WHEEL_ROOT_DIR)
shutil.copy(SOURCE_DIR / "readme.md", WHEEL_ROOT_DIR)
print("Copying resource files...")
shutil.copy(SOURCE_DIR / "source" / "MRViewer" / "MRDarkTheme.json", WHEEL_SRC_DIR)
shutil.copy(SOURCE_DIR / "source" / "MRViewer" / "MRLightTheme.json", WHEEL_SRC_DIR)
shutil.copy(SOURCE_DIR / "thirdparty" / "fontawesome-free" / "fa-solid-900.ttf", WHEEL_SRC_DIR)
shutil.copytree(SOURCE_DIR / "thirdparty" / "Noto_Sans", WHEEL_SRC_DIR, dirs_exist_ok=True)
shutil.copytree(SOURCE_DIR / "source" / "MRViewer" / "resource", WHEEL_SRC_DIR / "resource", dirs_exist_ok=True )
icon_resources = [
str(icon_resource.relative_to(WHEEL_SRC_DIR))
for icon_resource in (WHEEL_SRC_DIR / "resource").rglob("*.*") # no folders
]
font_resources = [
str(font_resources.relative_to(WHEEL_SRC_DIR))
for font_resources in (WHEEL_SRC_DIR).glob("NotoSans*.*") # no folders
]
pybind_shims = []
py_versions = []
for pybind_shim in LIB_DIR_MESHLIB.glob("*pybind11nonlimitedapi_meshlib_*"):
shutil.copy(pybind_shim, WHEEL_SRC_DIR)
pybind_shim_name = os.path.basename(pybind_shim)
pybind_shims.append(pybind_shim_name)
py_versions.append(int(re.sub("\\..*", "", re.sub(".*pybind11nonlimitedapi_meshlib_3\\.", "", pybind_shim_name))));
py_versions.sort()
shutil.copy(WHEEL_SCRIPT_DIR / "pyproject.toml", WHEEL_ROOT_DIR)
# generate setup.cfg
package_files = [
*pybind_shims,
*icon_resources,
"MRDarkTheme.json",
"MRLightTheme.json",
"fa-solid-900.ttf",
*font_resources
]
for module in modules:
package_files += [
f"{module}{LIB_EXTENSION}",
f"{module}.pyi",
]
with open(WHEEL_SCRIPT_DIR / "setup.cfg.in", 'r') as config_template_file:
config = Template(config_template_file.read()).substitute(
VERSION=version,
PACKAGE_DATA=", ".join(package_files),
PYTHON_TAG=".".join(f"py3{x}" for x in py_versions),
PLAT_NAME=plat_name,
)
with open(WHEEL_ROOT_DIR / "setup.cfg", 'w') as config_file:
config_file.write(config)
def build_wheel():
os.chdir(WHEEL_ROOT_DIR)
if SYSTEM == "Linux":
# Drop libz-ng.so.2 ZLIB_NG_* version requirements from every .so
# auditwheel will see -- the wheel's own modules in WHEEL_SRC_DIR
# (soon to be packed into the wheel) and the dep libs in LIB_DIR
# that auditwheel will pull in during repair. auditwheel has no
# manylinux policy entry for libz-ng, so leaving the tags in place
# fails the policy check.
# See scripts/wheel/strip_zlib_ng_symbol_versions.py for details.
subprocess.check_call(
[
sys.executable,
str(WHEEL_SCRIPT_DIR / "strip_zlib_ng_symbol_versions.py"),
str(LIB_DIR), str(WHEEL_SRC_DIR),
]
)
subprocess.check_call(
[sys.executable, "-m", "build", "--wheel"]
)
wheel_file = list(WHEEL_ROOT_DIR.glob("dist/*.whl"))[0]
if SYSTEM == "Linux":
# see also: https://github.com/mayeut/pep600_compliance
manylinux_version = "2_28"
os.chdir(WHEEL_ROOT_DIR)
subprocess.check_call(
[
sys.executable, "-m", "auditwheel",
"repair",
"--plat", f"manylinux_{manylinux_version}_{platform.machine()}",
wheel_file
]
)
print("Wheel files are ready:")
for repaired_wheel_file in WHEEL_ROOT_DIR.glob("wheelhouse/meshlib-*.whl"):
print(repaired_wheel_file)
elif SYSTEM == "Windows":
os.chdir(SOURCE_DIR)
subprocess.check_call(
[
sys.executable, "-m", "delvewheel",
"repair",
# We use --no-dll "msvcp140.dll;vcruntime140_1.dll;vcruntime140.dll" here to avoid strange conflict
# that happens if we pack these dlls into whl.
# Another option is to use --no-mangle "msvcp140.dll;vcruntime140_1.dll;vcruntime140.dll"
# to pack these dlls with original names and let system solve conflicts on import
# https://stackoverflow.com/questions/78817088/vsruntime-dlls-conflict-after-delvewheel-repair
# UPDATE:
# no longer needed due to https://github.com/adang1345/delvewheel/issues/49 fix with https://github.com/adang1345/delvewheel/commit/42a52cdcc15d424b030a94cb4b51a6b72e4a3d92
#"--no-dll", "msvcp140.dll;vcruntime140_1.dll;vcruntime140.dll",
"--add-path", LIB_DIR,
# This is needed to catch our `pybind11nonlimitedapi_meshlib_3.X.dll` on Windows. Otherwise they don't get patched,
# and then can't find `pybind11nonlimitedapi_stubs.dll`, which does get patched.
"--analyze-existing",
wheel_file
]
)
elif SYSTEM == "Darwin":
os.chdir(WHEEL_ROOT_DIR)
subprocess.check_call(
["delocate-path", "meshlib"]
)
os.chdir(SOURCE_DIR)
subprocess.check_call(
["delocate-wheel", "-w", ".", "-v", wheel_file]
)
if __name__ == "__main__":
csv = functools.partial(str.split, sep=",")
parser = ArgumentParser()
parser.add_argument("--version", required=True)
parser.add_argument("--modules", type=csv, default=MODULES)
parser.add_argument("--plat-name", default="any")
args = parser.parse_args()
try:
install_packages()
setup_workspace(version=args.version, modules=args.modules, plat_name=args.plat_name)
create_stubs.generate_stubs(modules=args.modules)
build_wheel()
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)