Download make_deploy_commit.py from princessamygdala/TreasureHuntForTwo: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/spaces/princessamygdala/TreasureHuntForTwo/resolve/main/make_deploy_commit.py
- Command line
-
hf download hf://spaces/princessamygdala/TreasureHuntForTwo/make_deploy_commit.py
-
curl -L -o make_deploy_commit.py https://huggingface.co/spaces/princessamygdala/TreasureHuntForTwo/resolve/main/make_deploy_commit.py
3.43 kB
| """Build the next hf-deploy commit from main, and say what /health will report. | |
| python make_deploy_commit.py -m "Deploy: what changed" | |
| git push hf hf-deploy:main # a human runs this | |
| WHY A SCRIPT. The Space is public, and the deploy tree used to be assembled by hand | |
| with two .docx removed by name. On 2026-11-09 a `git add -A` added an IRB procedure, a | |
| manuscript, its supplement and an Excel lock stub to main; the by-name list did not know | |
| about them, and only the order of two commits kept them off the Space. Everything matching | |
| EXCLUDE is dropped here, so a new document cannot ride along because someone forgot it. | |
| It never pushes. It writes the commit, moves the branch and prints the build hash to | |
| check afterwards, and the push stays a deliberate act by a person. | |
| """ | |
| import argparse | |
| import hashlib | |
| import os | |
| import subprocess | |
| import sys | |
| import tempfile | |
| #: Dropped from what the Space receives. Study documents and Office lock files. | |
| EXCLUDE = (".docx", ".doc", ".pdf", ".numbers", ".xlsx") | |
| EXCLUDE_PREFIX = ("~$",) | |
| #: The files /health hashes into the build id it reports. | |
| HEALTH_FILES = sorted(("web_app.py", "order_link.py", "experiment_structure.py", | |
| "orders.py", "questionnaires.py", "gitlab_save.py")) | |
| def git(*args, **kw): | |
| return subprocess.run(["git", *args], check=True, capture_output=True, | |
| text=True, **kw).stdout.strip() | |
| def excluded(path): | |
| base = path.rsplit("/", 1)[-1] | |
| return path.endswith(EXCLUDE) or base.startswith(EXCLUDE_PREFIX) | |
| def main(argv=None): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("-m", "--message", required=True, help="the deploy commit message") | |
| ap.add_argument("--source", default="main") | |
| ap.add_argument("--branch", default="hf-deploy") | |
| a = ap.parse_args(argv) | |
| if git("status", "--porcelain", "--untracked-files=no"): | |
| sys.exit("the working tree has uncommitted changes; commit them first") | |
| with tempfile.TemporaryDirectory() as tmp: | |
| env = dict(os.environ, GIT_INDEX_FILE=os.path.join(tmp, "index")) | |
| subprocess.run(["git", "read-tree", a.source], check=True, env=env) | |
| listing = subprocess.run(["git", "ls-tree", "-r", "--name-only", a.source], | |
| check=True, capture_output=True, text=True).stdout.split("\n") | |
| drop = [p for p in listing if p and excluded(p)] | |
| if drop: | |
| subprocess.run(["git", "update-index", "--force-remove", *drop], | |
| check=True, env=env) | |
| tree = subprocess.run(["git", "write-tree"], check=True, capture_output=True, | |
| text=True, env=env).stdout.strip() | |
| commit = subprocess.run(["git", "commit-tree", tree, "-p", a.branch], | |
| input=a.message, check=True, capture_output=True, | |
| text=True).stdout.strip() | |
| git("update-ref", f"refs/heads/{a.branch}", commit) | |
| h = hashlib.sha256() | |
| for name in HEALTH_FILES: | |
| h.update(subprocess.run(["git", "show", f"{a.branch}:{name}"], | |
| check=True, capture_output=True).stdout) | |
| print(f"{a.branch} -> {commit[:7]}") | |
| print(f"held back from the Space ({len(drop)}): " + ", ".join(drop)) | |
| print(f"\n/health should report build {h.hexdigest()[:12]} once it rebuilds") | |
| print(f"\n git push hf {a.branch}:main") | |
| if __name__ == "__main__": | |
| main() | |