forked from ChelseaKR/obligation-receipts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_wheel.py
More file actions
57 lines (50 loc) · 1.82 KB
/
Copy pathcheck_wheel.py
File metadata and controls
57 lines (50 loc) · 1.82 KB
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
50
51
52
53
54
55
56
57
"""Fail if the built wheel omits runtime modules or the PEP 561 marker."""
from __future__ import annotations
import sys
from pathlib import Path
from zipfile import BadZipFile, ZipFile
REQUIRED_MEMBERS = {
"obligation_receipts/__init__.py",
"obligation_receipts/canonical.py",
"obligation_receipts/cli.py",
"obligation_receipts/evaluator.py",
"obligation_receipts/manifest.py",
"obligation_receipts/models.py",
"obligation_receipts/paths.py",
"obligation_receipts/plan.py",
"obligation_receipts/py.typed",
"obligation_receipts/receipt.py",
"obligation_receipts/research.py",
"obligation_receipts/single_check.py",
}
def main(argv: list[str]) -> int:
if len(argv) != 1:
print("usage: check_wheel.py DIST_DIRECTORY", file=sys.stderr)
return 2
wheels = sorted(Path(argv[0]).glob("obligation_receipts-*.whl"))
if not wheels:
print("no obligation-receipts wheel found", file=sys.stderr)
return 2
wheel = wheels[-1]
try:
with ZipFile(wheel) as archive:
members = set(archive.namelist())
missing = sorted(REQUIRED_MEMBERS - members)
forbidden = sorted(
member
for member in members
if "__pycache__" in member or member.endswith(".pyc") or member.startswith("tests/")
)
except BadZipFile as exc:
print(f"invalid wheel {wheel}: {exc}", file=sys.stderr)
return 2
if missing:
print(f"wheel is missing required members: {', '.join(missing)}", file=sys.stderr)
return 2
if forbidden:
print(f"wheel contains forbidden members: {', '.join(forbidden)}", file=sys.stderr)
return 2
print(f"verified wheel contents: {wheel}")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))