Download code/scripts/update_provenance.py from CollinMa/nextgpt-chapter6-report: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/update_provenance.py
- Command line
-
hf download hf://spaces/CollinMa/nextgpt-chapter6-report/code/scripts/update_provenance.py
-
curl -L -o update_provenance.py https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/update_provenance.py
1.84 kB
| """Regenerate source checksums and the small vendor patch from the pinned checkout.""" | |
| import difflib | |
| import hashlib | |
| import json | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from settings import UPSTREAM_COMMIT | |
| def git(*args): | |
| return subprocess.check_output(["git", "-C", str(ROOT / "upstream"), *args]) | |
| if __name__ == "__main__": | |
| if git("rev-parse", "HEAD").decode().strip() != UPSTREAM_COMMIT: | |
| raise SystemExit("Unexpected upstream checkout revision.") | |
| prefix = "NExT-GPT-Lagacy/" | |
| paths = git("ls-tree", "-r", "--name-only", "HEAD", prefix).decode().splitlines() | |
| hashes, changes = {}, [] | |
| for path in paths: | |
| relative = path[len(prefix):] | |
| original = git("show", "HEAD:" + path) | |
| hashes[relative] = hashlib.sha256(original).hexdigest() | |
| local = (ROOT / "vendor" / "nextgpt" / relative).read_bytes() | |
| if relative.endswith(".py"): | |
| before = original.decode("utf-8").replace("\r\n", "\n") | |
| after = local.decode("utf-8").replace("\r\n", "\n") | |
| changes.extend(difflib.unified_diff(before.splitlines(True), after.splitlines(True), | |
| fromfile="a/vendor/nextgpt/"+relative, | |
| tofile="b/vendor/nextgpt/"+relative)) | |
| manifest = dict(project="nextgpt-chapter6-reproduction", upstream="https://github.com/NExT-GPT/NExT-GPT", | |
| commit=UPSTREAM_COMMIT, directory=prefix.rstrip("/"), original_sha256=hashes) | |
| (ROOT / "provenance.json").write_bytes((json.dumps(manifest, indent=2)+"\n").encode()) | |
| (ROOT / "vendor-patches.diff").write_bytes("".join(changes).encode()) | |
| print(f"Recorded {len(paths)} upstream files; {len(changes)} patch lines.") | |