Skip to content

Commit

Permalink
Fix RECORD file in merged Python wheel (#606)
Browse files Browse the repository at this point in the history
fixes #535
  • Loading branch information
t-sommer authored Oct 6, 2023
1 parent 2ecf902 commit c97ad02
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
8 changes: 2 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,10 @@ jobs:
downloadPath: windows

- bash: |
unzip -o linux/*.whl -d merged
unzip -o macosx/*.whl -d merged
unzip -o windows/*.whl -d merged
cd merged
zip -r FMPy-x.x.x-py3-none-any.whl .
python3 merge_wheels.py
displayName: Merge Python Wheels
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: merged/FMPy-x.x.x-py3-none-any.whl
pathtoPublish: merged
artifactName: merged
48 changes: 48 additions & 0 deletions merge_wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import shutil
import zipfile
from pathlib import Path
from shutil import make_archive, unpack_archive

root = Path(__file__).parent
merge = root / 'merge'
merged = root / 'merged'


if merge.exists():
shutil.rmtree(merge)

os.makedirs(merge)

if merged.exists():
shutil.rmtree(merged)

os.makedirs(merged)

wheels = []

for dirpath, dirnames, filenames in os.walk(root):
for filename in filenames:
if filename.endswith('.whl'):
wheels.append(root / dirpath / filename)

records = set()

for wheel in wheels:
with zipfile.ZipFile(wheel, 'r') as archive:
for info in archive.filelist:
if info.filename.endswith('RECORD'):
record = info.filename
break
records.update(archive.read(record).split(b'\n'))
archive.extractall(merge)

unpack_archive(wheel, merge, 'zip')

with open(merge / record, 'w') as record:
lines = [line.decode('utf-8') for line in records]
lines.sort()
record.writelines('\n'.join(lines))

make_archive(merged / wheels[0].stem, 'zip', merge)
os.rename(merged / (wheels[0].stem + '.zip'), merged / wheels[0].name)

0 comments on commit c97ad02

Please sign in to comment.