Skip to content

Commit fbfab10

Browse files
committed
[build] Repack wheel with maximum DEFLATE compression
Add a post-build step to recompress the wheel at compresslevel=9 (default is 6) to reduce artifact size.
1 parent b6ba3fa commit fbfab10

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

.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 maximum compression
181+
run: |
182+
python -c "
183+
import zipfile, os
184+
method = zipfile.ZIP_DEFLATED
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, compresslevel=9) 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 }}

0 commit comments

Comments
 (0)