StreamingOmniDatasets / scripts /100_refresh_release_checksums.py
skyzhou06's picture
Simplify public training schema from 105 to 27 columns
7afa8d9 verified
Raw History Blame Contribute Delete
1.11 kB
#!/usr/bin/env python3
"""Regenerate the publication checksum manifest after a validated projection."""
from __future__ import annotations
import hashlib
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "SHA256SUMS.txt"
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for block in iter(lambda: handle.read(8 << 20), b""):
digest.update(block)
return digest.hexdigest()
def main() -> None:
paths = sorted(
path
for path in ROOT.rglob("*")
if path.is_file()
and path != OUTPUT
and ".cache" not in path.relative_to(ROOT).parts
and "__pycache__" not in path.relative_to(ROOT).parts
and path.suffix != ".pyc"
and not path.name.endswith(".slim.tmp")
)
lines = [f"{sha256(path)} {path.relative_to(ROOT).as_posix()}" for path in paths]
tmp = OUTPUT.with_suffix(".txt.tmp")
tmp.write_text("\n".join(lines) + "\n")
tmp.replace(OUTPUT)
print(f"checksum_entries={len(paths)}")
if __name__ == "__main__":
main()