Files
UniversalHumanoid/tools/vendor_manifest.py
T
2026-11-03 19:46:08 +08:00

56 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Record or verify the repository vendor inventory (stdlib only, no simulator imports)."""
import argparse
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def inventory(root):
return {
str(p.relative_to(root)): hashlib.sha256(p.read_bytes()).hexdigest()
for p in sorted((root / "rl").rglob("*"))
if p.is_file() and "__pycache__" not in p.parts and p.name != "VENDOR.json"
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--record", action="store_true", help="Explicitly accept the current vendor inventory"
)
args = parser.parse_args()
path = ROOT / "rl/VENDOR.json"
files = inventory(ROOT)
imported = json.loads((ROOT / "rl/upstream/import.json").read_text())
if args.record:
original = imported["imported_files"]
modified = sorted(p for p in original if files.get(p) != original[p])
data = {
"schema_version": 1,
"files": files,
"changed_since_import": modified,
"added_since_import": sorted(set(files) - set(original)),
"upstream": {key: imported[key] for key in ("mjlab", "rsl_rl", "booster_assets")},
}
path.write_text(json.dumps(data, sort_keys=True, indent=2) + "\n")
print(
f"Recorded {len(files)} files. Review docs/VENDOR.md and the changes before committing."
)
else:
expected = json.loads(path.read_text())["files"]
changed = sorted(
p for p in files.keys() | expected.keys() if files.get(p) != expected.get(p)
)
print(
json.dumps({"ready": not changed, "files": len(files), "mismatches": changed}, indent=2)
)
raise SystemExit(bool(changed))
if __name__ == "__main__":
main()