Skip to content

Commit 697d63d

Browse files
authored
Implement license file stripping for wheel uploads
Added a function to strip license files from wheel packages before uploading.
1 parent 131ad9a commit 697d63d

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/backfill_wheels.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,24 @@ jobs:
5454
]
5555
5656
def pypi_eligible(name):
57-
if re.search(r"-pp\d|-graalpy|-cp313t-|-cp3\d\d-cp3\d\d-", name):
57+
if re.search(r"-pp\d|-graalpy|-cp313t-", name):
5858
return False
5959
return any(re.search(p, name) for p in PYPI_PLAT_KEEP)
6060
61+
def strip_license_file(whl_path):
62+
import zipfile, shutil
63+
tmp = str(whl_path) + ".tmp"
64+
with zipfile.ZipFile(whl_path, 'r') as zin, \
65+
zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED) as zout:
66+
for item in zin.infolist():
67+
data = zin.read(item.filename)
68+
if item.filename.endswith('METADATA'):
69+
lines = data.decode('utf-8').splitlines(keepends=True)
70+
data = ''.join(l for l in lines
71+
if not l.lower().startswith('license-file:')).encode('utf-8')
72+
zout.writestr(item, data)
73+
shutil.move(tmp, str(whl_path))
74+
6175
# ── GH API helpers ───────────────────────────────────────────────
6276
def gh(path):
6377
url = path if path.startswith("http") else f"https://api.github.com/repos/{repo}/{path}"
@@ -322,6 +336,9 @@ jobs:
322336
if not whl_files:
323337
continue
324338
339+
for wf_ in whl_files:
340+
strip_license_file(wf_)
341+
325342
result = subprocess.run(
326343
["twine", "upload", "--skip-existing", "--non-interactive",
327344
*[str(w) for w in whl_files]],

0 commit comments

Comments
 (0)