Download scripts/check_inputs.py from xuyun/CIP2A: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/datasets/xuyun/CIP2A/resolve/main/scripts/check_inputs.py
- Command line
-
hf download hf://datasets/xuyun/CIP2A/scripts/check_inputs.py
-
curl -L -o check_inputs.py https://huggingface.co/datasets/xuyun/CIP2A/resolve/main/scripts/check_inputs.py
1.67 kB
| """Compare locally obtained public inputs with the recorded release fingerprints.""" | |
| import argparse | |
| import csv | |
| import hashlib | |
| from pathlib import Path | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("names", nargs="+", help="Local names from the provenance CSVs") | |
| parser.add_argument("--inputs", type=Path, default=Path("inputs")) | |
| args = parser.parse_args() | |
| manifests = Path(__file__).resolve().parents[1] / "provenance" | |
| records = {} | |
| for filename in ("source_manifest.csv", "single_cell_and_rnai.csv"): | |
| with (manifests / filename).open(encoding="utf-8", newline="") as handle: | |
| records.update({row["local_name"]: row for row in csv.DictReader(handle)}) | |
| failures = [] | |
| for name in args.names: | |
| if name not in records: | |
| parser.error(f"Unknown source name: {name}") | |
| row = records[name] | |
| local = args.inputs / name | |
| if not local.is_file(): | |
| failures.append(f"{name}: local file missing") | |
| elif local.stat().st_size != int(row["bytes"]): | |
| failures.append(f"{name}: unexpected byte count") | |
| elif row["sha256"]: | |
| with local.open("rb") as handle: | |
| actual = hashlib.file_digest(handle, "sha256").hexdigest() | |
| if actual == row["sha256"].lower(): | |
| print(f"{name}: size and SHA-256 match") | |
| else: | |
| failures.append(f"{name}: SHA-256 mismatch") | |
| else: | |
| print(f"{name}: size matches; source SHA-256 was unavailable") | |
| if failures: | |
| raise SystemExit("\n".join(failures)) | |
| if __name__ == "__main__": | |
| main() | |