-
Notifications
You must be signed in to change notification settings - Fork 119
/
merge_wheels.py
49 lines (36 loc) · 1.19 KB
/
merge_wheels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()
lines = list(filter(lambda line: line != "", lines))
record.writelines('\n'.join(lines))
make_archive(str(merged / wheels[0].stem), 'zip', merge)
os.rename(merged / (wheels[0].stem + '.zip'), merged / wheels[0].name)