Skip to content

Commit 6c05f13

Browse files
committed
fix: Implement wheel platform tag renaming method
Added a method to rename wheel files by updating their platform tag while maintaining the filename format.
1 parent a4a8b28 commit 6c05f13

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

pythonforandroid/recipe.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from urllib.request import urlretrieve
1313
from os import listdir, unlink, environ, curdir, walk
1414
from sys import stdout
15+
from pathlib import Path
1516
from multiprocessing import cpu_count
1617
import time
1718
try:
@@ -1278,31 +1279,57 @@ def get_wheel_platform_tag(self, arch):
12781279
"x86": "i686",
12791280
}[arch.arch]
12801281

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+
12811312
def install_wheel(self, arch, built_wheels):
12821313
with patch_wheel_setuptools_logging():
1283-
from wheel.cli.tags import tags as wheel_tags
12841314
from wheel.wheelfile import WheelFile
12851315
_wheel = built_wheels[0]
1286-
built_wheel_dir = dirname(_wheel)
12871316
# Fix wheel platform tag
1288-
wheel_tag = wheel_tags(
1317+
selected_wheel = self._retag_wheel_platform(
12891318
_wheel,
1290-
platform_tags=self.get_wheel_platform_tag(arch),
1291-
remove=True,
1319+
self.get_wheel_platform_tag(arch),
1320+
remove_old=True,
12921321
)
1293-
selected_wheel = join(built_wheel_dir, wheel_tag)
12941322

12951323
_dev_wheel_dir = environ.get("P4A_WHEEL_DIR", False)
12961324
if _dev_wheel_dir:
12971325
ensure_dir(_dev_wheel_dir)
12981326
shprint(sh.cp, selected_wheel, _dev_wheel_dir)
12991327

1300-
info(f"Installing built wheel: {wheel_tag}")
1328+
info(f"Installing built wheel: {basename(selected_wheel)}")
13011329
destination = self.ctx.get_python_install_dir(arch.arch)
13021330
with WheelFile(selected_wheel) as wf:
13031331
for zinfo in wf.filelist:
13041332
wf.extract(zinfo, destination)
1305-
wf.close()
13061333

13071334
def build_arch(self, arch):
13081335

0 commit comments

Comments
 (0)