| |
| from pathlib import Path |
| import hashlib |
| import argparse |
|
|
|
|
| parser = argparse.ArgumentParser() |
| parser.add_argument("--root", default=".") |
| parser.add_argument("--out", default="SHA256SUMS.txt") |
| parser.add_argument("--exclude-dist", action="store_true") |
| parser.add_argument("--include-safe-subset", action="store_true") |
| args = parser.parse_args() |
|
|
| root = Path(args.root) |
| files = [] |
|
|
|
|
| def is_lfs_pointer(path): |
| try: |
| return path.read_bytes()[:120].startswith(b"version https://git-lfs.github.com/spec/v1") |
| except OSError: |
| return False |
|
|
|
|
| for p in root.rglob("*"): |
| if not p.is_file(): |
| continue |
| rel = p.relative_to(root).as_posix() |
| if rel == args.out: |
| continue |
| if args.exclude_dist and rel.startswith("dist/"): |
| continue |
| if not args.include_safe_subset and rel.startswith("safe_public_subset/"): |
| continue |
| if ".git/" in rel or rel.startswith(".git/"): |
| continue |
| if "__pycache__/" in rel or rel.endswith(".pyc"): |
| continue |
| files.append(p) |
|
|
| lines = [] |
| pointer_files = [] |
| for p in sorted(files): |
| if is_lfs_pointer(p): |
| pointer_files.append(p.relative_to(root).as_posix()) |
| h = hashlib.sha256(p.read_bytes()).hexdigest() |
| lines.append(f"{h} {p.relative_to(root).as_posix()}") |
|
|
| Path(args.out).write_text("\n".join(lines) + "\n", encoding="utf-8") |
| print(f"Wrote {args.out} with {len(lines)} files") |
| if pointer_files: |
| print("Warning: hashed Git LFS pointer files, not full payloads:") |
| for rel in pointer_files: |
| print(f"- {rel}") |
|
|