Files
2026-11-03 19:46:08 +08:00

68 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Ensure a built wheel contains exact backend sources, robot assets and licence resources."""
import argparse
import email
import json
import tomllib
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("wheel", type=Path)
args = parser.parse_args()
missing, changed = [], []
checked = 0
license_files = 0
with zipfile.ZipFile(args.wheel) as archive:
names = set(archive.namelist())
for source_root, package in (
(ROOT / "src", "universal_humanoid"),
(ROOT / "rl", "mjlab"),
(ROOT / "rl", "rsl_rl"),
):
for source in sorted((source_root / package).rglob("*")):
if not source.is_file() or "__pycache__" in source.parts:
continue
name = source.relative_to(source_root).as_posix()
checked += 1
if name not in names:
missing.append(name)
elif archive.read(name) != source.read_bytes():
changed.append(name)
metadata_names = [name for name in names if name.endswith(".dist-info/METADATA")]
if len(metadata_names) != 1:
raise ValueError("Expected exactly one wheel distribution metadata record")
metadata_name = metadata_names[0]
metadata = email.message_from_bytes(archive.read(metadata_name))
project = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]
if metadata.get("License-Expression") != project["license"]:
changed.append(metadata_name + ":License-Expression")
prefix = metadata_name.removesuffix("METADATA") + "licenses/"
for pattern in project["license-files"]:
for source in sorted(ROOT.glob(pattern)):
name = prefix + source.relative_to(ROOT).as_posix()
license_files += 1
if name not in names:
missing.append(name)
elif archive.read(name) != source.read_bytes():
changed.append(name)
report = {
"ready": not missing and not changed,
"checked": checked,
"license_files": license_files,
"missing": missing,
"changed": changed,
"wheel": str(args.wheel),
}
print(json.dumps(report, indent=2))
raise SystemExit(0 if report["ready"] else 1)
if __name__ == "__main__":
main()