Skip to content

Commit 8bed6a9

Browse files
authored
Merge pull request #198 from robotpy/fix-wheel-names
Use auditwheel to detect the correct names for built wheels in CI
2 parents a4ecaca + ea57e01 commit 8bed6a9

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

devtools/subproject.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ def build_wheel(
132132

133133
tdp = pathlib.Path(td)
134134
twhl = list(tdp.glob("*.whl"))[0]
135-
dst_whl = wheel_path / self._fix_wheel_name(twhl.name)
135+
dst_whl = wheel_path / self._fix_wheel_name(twhl)
136136
shutil.move(twhl, dst_whl)
137+
print("Wrote wheel to", dst_whl)
137138

138139
if install:
139140
# Install the wheel
@@ -147,19 +148,46 @@ def build_wheel(
147148
)
148149

149150
_adjust_wheel_tags = {
150-
# pypi only accepts manylinux wheels, and we know we're compatible
151-
# TODO(davo): use auditwheel to fix the tags instead
152-
"linux_x86_64": "manylinux_2_35_x86_64",
153-
"linux_aarch64": "manylinux_2_36_aarch64",
154151
# needed for compatibility with python compiled with older xcode
155152
"macosx_11_0_x86_64": "macosx_10_16_x86_64",
156153
"macosx_12_0_x86_64": "macosx_10_16_x86_64",
157154
}
158155

159-
def _fix_wheel_name(self, name: str) -> str:
160-
for old, new in self._adjust_wheel_tags.items():
161-
old_whl = f"{old}.whl"
162-
new_whl = f"{new}.whl"
163-
if name.endswith(old_whl):
164-
name = f"{name[:-len(old_whl)]}{new_whl}"
156+
def _fix_wheel_name(self, wheel_path: pathlib.Path) -> str:
157+
if sys.platform == "linux":
158+
name = self._fix_linux_wheel_name(wheel_path)
159+
else:
160+
name = wheel_path.name
161+
for old, new in self._adjust_wheel_tags.items():
162+
old_whl = f"{old}.whl"
163+
new_whl = f"{new}.whl"
164+
if name.endswith(old_whl):
165+
name = f"{name[:-len(old_whl)]}{new_whl}"
166+
165167
return name
168+
169+
def _fix_linux_wheel_name(self, wheel_path: pathlib.Path) -> str:
170+
# inspired by https://github.com/hsorby/renamewheel, Apache license
171+
172+
from auditwheel.error import NonPlatformWheel, WheelToolsError
173+
from auditwheel.wheel_abi import analyze_wheel_abi
174+
from auditwheel.wheeltools import get_wheel_architecture, get_wheel_libc
175+
176+
try:
177+
arch = get_wheel_architecture(wheel_path.name)
178+
except (WheelToolsError, NonPlatformWheel):
179+
arch = None
180+
181+
try:
182+
libc = get_wheel_libc(wheel_path.name)
183+
except WheelToolsError:
184+
libc = None
185+
186+
try:
187+
winfo = analyze_wheel_abi(libc, arch, wheel_path, frozenset(), True, True)
188+
except NonPlatformWheel:
189+
return wheel_path.name
190+
else:
191+
parts = wheel_path.name.split("-")
192+
parts[-1] = winfo.overall_policy.name
193+
return "-".join(parts) + ".whl"

rdev_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ validobj~=1.2
1010

1111
ninja
1212
msvc-runtime>=14.42.34433; platform_system == 'Windows'
13+
14+
auditwheel~=6.4; platform_system == 'Linux'

0 commit comments

Comments
 (0)