-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_distinfo.py
35 lines (29 loc) · 1.15 KB
/
write_distinfo.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
#!/usr/bin/env python
import os
import hashlib
import base64
import sys
if len(sys.argv) != 4:
raise ValueError("no name/version/tag")
name, version, tag = sys.argv[1:]
path = os.path.join(f"{name}-{version}.dist-info", "WHEEL")
with open(path, "w") as wheel:
wheel.write("Wheel-Version: 1.0\n")
wheel.write("Generator: custom\n")
wheel.write("Root-Is-Purelib: false\n")
wheel.write(f"Tag: {tag}\n")
path = os.path.join(f"{name}-{version}.dist-info", "RECORD")
with open(path, "w") as record:
for subdir in [name, f"{name}-{version}.dist-info"]:
for root, dirs, files in os.walk(subdir):
for fn in files:
fpath = os.path.join(root, fn)
if os.path.isfile(fpath):
if fn == "RECORD":
record.write(f"{fpath},,\n")
else:
data = open(fpath, "rb").read()
digest = hashlib.sha256(data).digest()
checksum = base64.urlsafe_b64encode(digest).decode()
size = len(data)
record.write(f"{fpath},sha256={checksum},{size}\n")