Download scripts/fetch_upstream.py from clhfy45/ah: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/clhfy45/ah/resolve/main/scripts/fetch_upstream.py
- Command line
-
hf download hf://spaces/clhfy45/ah/scripts/fetch_upstream.py
-
curl -L -o fetch_upstream.py https://huggingface.co/spaces/clhfy45/ah/resolve/main/scripts/fetch_upstream.py
1.44 kB
| import io | |
| import json | |
| import os | |
| import re | |
| import sys | |
| import tarfile | |
| import urllib.request | |
| from pathlib import Path | |
| def main(): | |
| manifest = json.loads(Path("upstream.json").read_text()) | |
| revision = manifest["commit"] | |
| if not re.fullmatch(r"[0-9a-f]{40}", revision): | |
| raise SystemExit("upstream.json 必须固定完整提交 SHA") | |
| url = f"https://api.github.com/repos/Comfy-Org/ComfyUI/tarball/{revision}" | |
| headers = {"User-Agent": "comfy-space-build"} | |
| if os.environ.get("GITHUB_TOKEN"): | |
| headers["Authorization"] = "Bearer " + os.environ["GITHUB_TOKEN"] | |
| with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=120) as response: | |
| archive_bytes = response.read() | |
| destination = Path(sys.argv[1]) | |
| destination.mkdir(parents=True, exist_ok=True) | |
| with tarfile.open(fileobj=io.BytesIO(archive_bytes)) as archive: | |
| for member in archive.getmembers(): | |
| parts = Path(member.name).parts[1:] | |
| if not parts: | |
| continue | |
| member.name = str(Path(*parts)) | |
| archive.extract(member, destination, filter="data") | |
| code = (destination / "comfyui_version.py").read_text() | |
| if f'"{manifest["version"].removeprefix("v")}"' not in code: | |
| raise SystemExit("提交 SHA 与声明的 ComfyUI 版本不一致") | |
| print("已下载并验证 ComfyUI " + manifest["version"]) | |
| if __name__ == "__main__": | |
| main() | |