Skip to content

Commit 9b08db7

Browse files
committed
Updated the retag_wheel_py3-none.py file with new content.
1 parent b9c2bac commit 9b08db7

File tree

3 files changed

+42
-56
lines changed

3 files changed

+42
-56
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ jobs:
4545
CIBW_ARCHS: native # avoid building extra archs unintentionally
4646
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
4747
CIBW_BUILD_VERBOSITY: 1
48-
49-
# Retag to py3-none-<platform>
50-
CIBW_REPAIR_WHEEL_COMMAND: "python tools/retag_wheel_py3-none.py {wheel}"
48+
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ${{ matrix.platform_id == 'macosx_arm64' && 'delocate-wheel -w {dest_dir} -v {wheel}' || 'delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}' }}
5149
with:
5250
output-dir: wheelhouse
5351

52+
- name: Retag wheels to py3-none-<platform>
53+
run: python tools/retag_wheel_py3-none.py wheelhouse
54+
5455
- name: Install dependencies (Linux)
5556
run: sudo apt update && sudo apt install -y --no-install-recommends graphviz
5657
if: startsWith(matrix.os, 'ubuntu')
@@ -127,3 +128,4 @@ jobs:
127128
uses: pypa/gh-action-pypi-publish@release/v1
128129
with:
129130
skip-existing: true
131+
verbose: true

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [ubuntu-latest, macos-latest-large]
15+
os: [ubuntu-latest, macos-latest-large, macos-latest]
1616
python: ['3.10', '3.12']
1717
steps:
1818
- uses: actions/checkout@v5

tools/retag_wheel_py3-none.py

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,61 @@
1-
"""
2-
Rewrite wheel tags from cp312-cp312-PLATFORM to py3-none-PLATFORM.
3-
4-
This is appropriate when the wheel contains OS-specific non-Python binaries
5-
(e.g., Inform7) but no Python extension modules (ABI-independent).
6-
"""
1+
"""Retag wheel from cpXYZ-cpXYZ-PLATFORM to py3-none-PLATFORM."""
72

83
import argparse
94
import os
10-
import re
115
import zipfile
126
from pathlib import Path
137

148

15-
WHEEL_TAG_RE = re.compile(r"^Tag:\s*(\S+)\s*$")
16-
17-
18-
def parse_platform_tag(filename: str) -> str:
19-
# {dist}-{ver}-{python tag}-{abi tag}-{platform tag}.whl
20-
m = re.match(r"^.+-[^-]+-[^-]+-(?P<plat>.+)\.whl$", filename)
21-
if not m:
22-
raise ValueError(f"Cannot parse wheel filename: {filename}")
23-
return m.group("plat")
24-
25-
269
def retag(path: Path) -> Path:
27-
plat = parse_platform_tag(path.name)
28-
new_name = re.sub(r"-[^-]+-[^-]+-" + re.escape(plat) + r"\.whl$", f"-py3-none-{plat}.whl", path.name)
29-
# If the regex didn't match (unexpected format), fall back to explicit construction:
30-
if new_name == path.name:
31-
# Use a more explicit split
32-
parts = path.name[:-4].split("-")
33-
if len(parts) < 5:
34-
raise ValueError(f"Unexpected wheel name: {path.name}")
35-
new_name = "-".join(parts[:-3] + ["py3", "none", parts[-1]]) + ".whl"
36-
10+
# Extract platform tag from filename: name-ver-pytag-abi-platform.whl
11+
parts = path.stem.split("-")
12+
platform = parts[-1]
13+
new_name = "-".join(parts[:-3] + ["py3", "none", platform]) + ".whl"
3714
out = path.with_name(new_name)
3815

39-
with zipfile.ZipFile(path, "r") as zin, zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED) as zout:
40-
wheel_files = [n for n in zin.namelist() if n.endswith(".dist-info/WHEEL")]
41-
if len(wheel_files) != 1:
42-
raise RuntimeError(f"Expected exactly one .dist-info/WHEEL, found: {wheel_files}")
43-
wheel_meta = wheel_files[0]
16+
with zipfile.ZipFile(path, "r") as zin, zipfile.ZipFile(
17+
out, "w", compression=zipfile.ZIP_DEFLATED
18+
) as zout:
19+
wheel_meta = next(n for n in zin.namelist() if n.endswith(".dist-info/WHEEL"))
4420

4521
for info in zin.infolist():
4622
data = zin.read(info.filename)
47-
if info.filename == wheel_meta:
48-
text = data.decode("utf-8")
49-
lines = text.splitlines(True)
50-
51-
kept = []
52-
for line in lines:
53-
if WHEEL_TAG_RE.match(line.strip()):
54-
continue
55-
kept.append(line)
5623

57-
kept.append(f"Tag: py3-none-{plat}\n")
58-
data = "".join(kept).encode("utf-8")
24+
if info.filename == wheel_meta:
25+
lines = data.decode("utf-8").splitlines(keepends=True)
26+
# Remove existing Tag: lines and add new one
27+
lines = [l for l in lines if not l.strip().startswith("Tag:")]
28+
if lines and not lines[-1].endswith("\n"):
29+
lines[-1] += "\n"
30+
lines.append(f"Tag: py3-none-{platform}\n")
31+
data = "".join(lines).encode("utf-8")
5932

6033
zout.writestr(info, data)
6134

62-
# Remove original so only retagged wheel remains
63-
os.remove(path)
35+
try:
36+
os.remove(path)
37+
except OSError:
38+
pass
39+
6440
return out
6541

6642

6743
def main() -> None:
68-
ap = argparse.ArgumentParser()
69-
ap.add_argument("wheel", nargs="+")
70-
args = ap.parse_args()
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument("dest_dir", type=Path, help="Directory containing wheels to retag")
46+
args = parser.parse_args()
47+
48+
if not args.dest_dir.is_dir():
49+
raise ValueError(f"Directory not found: {args.dest_dir}")
50+
51+
wheels = list(args.dest_dir.glob("*.whl"))
52+
if not wheels:
53+
print(f"No wheels found in {args.dest_dir}")
54+
return
7155

72-
for w in args.wheel:
73-
out = retag(Path(w))
74-
print(f"Retagged: {w} -> {out.name}")
56+
for wheel in wheels:
57+
out = retag(wheel)
58+
print(f"Retagged: {wheel.name} -> {out.name}")
7559

7660

7761
if __name__ == "__main__":

0 commit comments

Comments
 (0)