Download scripts/setup-repository.py from nmarshall/nanobrush: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/nmarshall/nanobrush/resolve/main/scripts/setup-repository.py
- Command line
-
hf download hf://nmarshall/nanobrush/scripts/setup-repository.py
-
curl -L -o setup-repository.py https://huggingface.co/nmarshall/nanobrush/resolve/main/scripts/setup-repository.py
1.73 kB
| #!/usr/bin/env python3 | |
| """Install the committed storage policy in this checkout's local Git config.""" | |
| from pathlib import Path | |
| import shlex | |
| import subprocess | |
| import sys | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def main(): | |
| if not (ROOT / ".git").exists(): | |
| raise SystemExit("Run setup in a Git checkout, not a Nix store source copy.") | |
| def git(*args): | |
| return subprocess.check_output(["git", "-C", str(ROOT), *args], text=True).strip() | |
| existing = subprocess.run(["git", "-C", str(ROOT), "config", "--local", "--get", "core.hooksPath"], | |
| text=True, capture_output=True).stdout.strip() | |
| if existing and existing != ".githooks": | |
| raise SystemExit(f"Existing hooksPath {existing!r}: integrate it before replacing hooks.") | |
| git("lfs", "version") | |
| git("xet", "--version") | |
| git("lfs", "install", "--local", "--skip-repo") | |
| git("xet", "install", "--local") | |
| git("config", "--local", "lfs.basictransfersonly", "false") | |
| python = shlex.quote(sys.executable) | |
| script = shlex.quote(str(ROOT / "scripts/storage_policy.py")) | |
| # Git shell-quotes its %f substitution. Keep it as a distinct argument. | |
| git("config", "--local", "filter.nanobrush-code.clean", f"{python} {script} clean -- %f") | |
| git("config", "--local", "filter.nanobrush-code.smudge", "cat") | |
| git("config", "--local", "filter.nanobrush-code.required", "true") | |
| git("config", "--local", "core.hooksPath", ".githooks") | |
| for name in ("pre-commit", "pre-push"): | |
| path = ROOT / ".githooks" / name | |
| path.chmod(path.stat().st_mode | 0o111) | |
| print("Installed local code/LFS filters, Xet transfers and commit/push guards.") | |
| if __name__ == "__main__": | |
| main() | |