|
12 | 12 | from urllib.request import urlretrieve |
13 | 13 | from os import listdir, unlink, environ, curdir, walk |
14 | 14 | from sys import stdout |
| 15 | +from pathlib import Path |
15 | 16 | from multiprocessing import cpu_count |
16 | 17 | import time |
17 | 18 | try: |
@@ -1278,31 +1279,57 @@ def get_wheel_platform_tag(self, arch): |
1278 | 1279 | "x86": "i686", |
1279 | 1280 | }[arch.arch] |
1280 | 1281 |
|
| 1282 | + def _retag_wheel_platform(self, path, new_platform_tag, remove_old=True): |
| 1283 | + """ |
| 1284 | + Rename a wheel by replacing only its platform tag. |
| 1285 | +
|
| 1286 | + Wheel filename format: |
| 1287 | + {dist}-{version}(-{build})?-{python tag}-{abi tag}-{platform tag}.whl |
| 1288 | +
|
| 1289 | + We split from the right so project names/build tags containing '-' still work. |
| 1290 | + """ |
| 1291 | + p = Path(path) |
| 1292 | + if p.suffix != ".whl": |
| 1293 | + raise ValueError(f"Not a wheel: {path}") |
| 1294 | + |
| 1295 | + parts = p.stem.rsplit("-", 3) |
| 1296 | + if len(parts) != 4: |
| 1297 | + raise ValueError(f"Unexpected wheel filename format: {p.name}") |
| 1298 | + |
| 1299 | + left, py_tag, abi_tag, _old_platform_tag = parts |
| 1300 | + new_name = f"{left}-{py_tag}-{abi_tag}-{new_platform_tag}.whl" |
| 1301 | + new_path = p.with_name(new_name) |
| 1302 | + |
| 1303 | + if new_path != p: |
| 1304 | + p.rename(new_path) |
| 1305 | + if not remove_old and new_path != p: |
| 1306 | + # rename already removed old path, so if you truly want both, |
| 1307 | + # copy instead of rename |
| 1308 | + pass |
| 1309 | + |
| 1310 | + return str(new_path) |
| 1311 | + |
1281 | 1312 | def install_wheel(self, arch, built_wheels): |
1282 | 1313 | with patch_wheel_setuptools_logging(): |
1283 | | - from wheel.cli.tags import tags as wheel_tags |
1284 | 1314 | from wheel.wheelfile import WheelFile |
1285 | 1315 | _wheel = built_wheels[0] |
1286 | | - built_wheel_dir = dirname(_wheel) |
1287 | 1316 | # Fix wheel platform tag |
1288 | | - wheel_tag = wheel_tags( |
| 1317 | + selected_wheel = self._retag_wheel_platform( |
1289 | 1318 | _wheel, |
1290 | | - platform_tags=self.get_wheel_platform_tag(arch), |
1291 | | - remove=True, |
| 1319 | + self.get_wheel_platform_tag(arch), |
| 1320 | + remove_old=True, |
1292 | 1321 | ) |
1293 | | - selected_wheel = join(built_wheel_dir, wheel_tag) |
1294 | 1322 |
|
1295 | 1323 | _dev_wheel_dir = environ.get("P4A_WHEEL_DIR", False) |
1296 | 1324 | if _dev_wheel_dir: |
1297 | 1325 | ensure_dir(_dev_wheel_dir) |
1298 | 1326 | shprint(sh.cp, selected_wheel, _dev_wheel_dir) |
1299 | 1327 |
|
1300 | | - info(f"Installing built wheel: {wheel_tag}") |
| 1328 | + info(f"Installing built wheel: {basename(selected_wheel)}") |
1301 | 1329 | destination = self.ctx.get_python_install_dir(arch.arch) |
1302 | 1330 | with WheelFile(selected_wheel) as wf: |
1303 | 1331 | for zinfo in wf.filelist: |
1304 | 1332 | wf.extract(zinfo, destination) |
1305 | | - wf.close() |
1306 | 1333 |
|
1307 | 1334 | def build_arch(self, arch): |
1308 | 1335 |
|
|
0 commit comments