Skip to content

Commit ec3dea1

Browse files
committed
[build] Repack wheel with LZMA compression
Add a post-build step to recompress the wheel using LZMA (ZIP_LZMA), which reduces size by ~35% compared to the default DEFLATE. This brings the wheel under the 2 GiB GitHub release limit.
1 parent b6ba3fa commit ec3dea1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ jobs:
177177
python setup.py $SKIP_CMAKE bdist_wheel --py-limited-api=cp37 --dist-dir="$PWD\wheelhouse" -v
178178
shell: pwsh
179179

180+
- name: Repack wheel with LZMA compression
181+
run: |
182+
python -c "
183+
import zipfile, os
184+
method = zipfile.ZIP_LZMA
185+
whl_dir = 'wheelhouse'
186+
for name in os.listdir(whl_dir):
187+
if not name.endswith('.whl'):
188+
continue
189+
src = os.path.join(whl_dir, name)
190+
dst = src + '.tmp'
191+
src_size = os.path.getsize(src)
192+
print(f'Repacking {name} ({src_size / 1e9:.2f} GB)...')
193+
with zipfile.ZipFile(src, 'r') as zin, zipfile.ZipFile(dst, 'w', method) as zout:
194+
for item in zin.infolist():
195+
item.compress_type = method
196+
zout.writestr(item, zin.read(item.filename))
197+
dst_size = os.path.getsize(dst)
198+
saved = src_size - dst_size
199+
print(f'Done: {dst_size / 1e9:.2f} GB (saved {saved / 1e6:.1f} MB, {100*saved/src_size:.1f}%)')
200+
os.replace(dst, src)
201+
"
202+
shell: bash
203+
180204
- name: Save build artifacts to cache
181205
uses: actions/cache/save@v3
182206
if: ${{ inputs.save_build_cache && !inputs.rolling_build }}

docs/workflow.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ gh run view <run-id> -R Breakthrough/opencv-python-cuda
106106

107107
---
108108

109+
## Wheel Compression
110+
111+
The build workflow repacks the output wheel using LZMA (`ZIP_LZMA`) compression instead of the default DEFLATE. This reduces the wheel size by ~35%, which is necessary to stay under the 2 GiB GitHub release file size limit.
112+
113+
While the [wheel spec (PEP 427)](https://peps.python.org/pep-0427/) defines wheels as ZIP archives, it does not specify which ZIP compression methods are permitted. In practice, LZMA works because both pip and uv delegate decompression to their respective ZIP libraries (Python's `zipfile` module and Rust's `zip` crate), both of which support LZMA natively. This has been verified with pip (anything compatible the standard [`zipfile` module](https://docs.python.org/3/library/zipfile.html)) and uv (which uses the [`zip` crate](https://crates.io/crates/zip)).
114+
115+
---
116+
109117
## Reference: Git Config for Remotes
110118

111119
After setup, your `.git/config` remote sections should look like:

0 commit comments

Comments
 (0)