Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / scripts /update_sha256sums.py
Zipeng365's picture
wisp-har 0.3.0: scikit-learn interface, recipe catalog, Optuna search, cost-accuracy figures
4731b11 verified
Raw History Blame Contribute Delete
1.6 kB
"""Rewrite SHA256SUMS for the files of this tree, keeping the lines of files that live only on
the Hub (``models/``, ``videos/``), which this tree does not contain.
python scripts/update_sha256sums.py [--check]
Hashed: every git-tracked file (except SHA256SUMS itself) plus wheels in ``dist/``.
"""
from __future__ import annotations
import argparse
import hashlib
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
KEEP_PREFIXES = ("models/", "videos/")
def sha256(path: Path) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
for chunk in iter(lambda: f.read(1 << 20), b""):
h.update(chunk)
return h.hexdigest()
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--check", action="store_true")
a = ap.parse_args()
target = ROOT / "SHA256SUMS"
kept = [line for line in target.read_text().splitlines() if line[66:].startswith(KEEP_PREFIXES)]
files = subprocess.run(["git", "ls-files"], cwd=ROOT, capture_output=True, text=True, check=True).stdout.split()
files += [str(p.relative_to(ROOT)) for p in sorted((ROOT / "dist").glob("*.whl"))]
lines = [f"{sha256(ROOT / f)} {f}" for f in sorted(set(files)) if f != "SHA256SUMS" and (ROOT / f).is_file()]
text = "\n".join(sorted(lines + kept, key=lambda line: line[66:])) + "\n"
if a.check:
raise SystemExit(0 if target.read_text() == text else "SHA256SUMS is out of date")
target.write_text(text)
print(f"{len(lines)} tree files, {len(kept)} Hub-only lines kept")
if __name__ == "__main__":
main()