ProCreations's picture
Publish validated ICML reproduction
c692cd7 verified
Raw
History Blame Contribute Delete
952 Bytes
#!/usr/bin/env python3
from __future__ import annotations
import argparse,hashlib
from pathlib import Path
ROOT=Path(__file__).resolve().parent;OUT=ROOT/"BUNDLE_SHA256SUMS.txt"
def digest(path:Path)->str:
value=hashlib.sha256()
with path.open("rb") as handle:
for block in iter(lambda:handle.read(1<<20),b""):value.update(block)
return value.hexdigest()
def rows()->list[str]:return [f"{digest(path)} {path.relative_to(ROOT).as_posix()}" for path in sorted(ROOT.rglob("*")) if path.is_file() and path!=OUT and "__pycache__" not in path.parts]
parser=argparse.ArgumentParser();parser.add_argument("--verify",action="store_true");args=parser.parse_args();rendered="\n".join(rows())+"\n"
if args.verify:
if not OUT.exists() or OUT.read_text(encoding="utf-8")!=rendered:raise SystemExit("manifest mismatch")
print(f"verified {len(rows())} entries")
else:OUT.write_text(rendered,encoding="utf-8");print(f"wrote {len(rows())} entries to {OUT.name}")