Skip to content

Commit f104f0c

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 f104f0c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ 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+
whl_dir = 'wheelhouse'
185+
for name in os.listdir(whl_dir):
186+
if not name.endswith('.whl'):
187+
continue
188+
src = os.path.join(whl_dir, name)
189+
dst = src + '.tmp'
190+
src_size = os.path.getsize(src)
191+
print(f'Repacking {name} ({src_size / 1e9:.2f} GB)...')
192+
with zipfile.ZipFile(src, 'r') as zin, zipfile.ZipFile(dst, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as zout:
193+
for item in zin.infolist():
194+
zout.writestr(item, zin.read(item.name))
195+
dst_size = os.path.getsize(dst)
196+
saved = src_size - dst_size
197+
print(f'Done: {dst_size / 1e9:.2f} GB (saved {saved / 1e6:.1f} MB, {100*saved/src_size:.1f}%)')
198+
os.replace(dst, src)
199+
"
200+
shell: bash
201+
180202
- name: Save build artifacts to cache
181203
uses: actions/cache/save@v3
182204
if: ${{ inputs.save_build_cache && !inputs.rolling_build }}

0 commit comments

Comments
 (0)