Skip to content

Commit 06ba3c7

Browse files
committed
fix: strip trailing data from wheels immediately after build
Move wheel stripping from publish-pypi to build-wheels job. This fixes validation failures where validate-wheels detects trailing data before publish-pypi can strip it. The Windows build with certain Rust/PyO3 versions adds trailing NULL bytes that cause PyPI upload failures.
1 parent 1a02491 commit 06ba3c7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

.github/workflows/release-automated.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,43 @@ jobs:
154154
manylinux: auto # Use manylinux_2_28 where available
155155
docker-options: -e CI # Pass CI env to docker
156156

157+
# Fix: Strip trailing data from wheels immediately after build
158+
# Windows builds with certain Rust/PyO3 versions add trailing NULL bytes
159+
# that cause PyPI upload failures. Strip them here before uploading artifacts.
160+
- name: Strip trailing data from wheels
161+
shell: python
162+
run: |
163+
from pathlib import Path
164+
165+
def strip_trailing_data(wheel_path):
166+
"""Remove trailing bytes after ZIP End of Central Directory."""
167+
with open(wheel_path, 'rb') as f:
168+
data = f.read()
169+
170+
eocd_sig = b'PK\x05\x06'
171+
pos = data.rfind(eocd_sig)
172+
173+
if pos == -1:
174+
print(f" Warning: No EOCD found in {wheel_path.name}")
175+
return False
176+
177+
comment_len = int.from_bytes(data[pos+20:pos+22], 'little')
178+
eocd_end = pos + 22 + comment_len
179+
trailing_bytes = len(data) - eocd_end
180+
181+
if trailing_bytes > 0:
182+
print(f" Stripped {trailing_bytes} trailing bytes from {wheel_path.name}")
183+
with open(wheel_path, 'wb') as f:
184+
f.write(data[:eocd_end])
185+
return True
186+
return False
187+
188+
dist_dir = Path('dist')
189+
wheels = list(dist_dir.glob('*.whl'))
190+
fixed = sum(1 for w in wheels if strip_trailing_data(w))
191+
if fixed:
192+
print(f"Fixed {fixed} wheel(s)")
193+
157194
- name: Upload wheels
158195
uses: actions/upload-artifact@v5
159196
with:

0 commit comments

Comments
 (0)