belcour/hypernetwork
0
1"""Install private GitHub dependencies at runtime (HF build secrets are unreliable for pip git URLs)."""2 3from __future__ import annotations4 5import importlib.util6import os7import subprocess8import sys9 10GITHUB_REPO = "belcour/egsr2026_hypernetwork"11PACKAGE = "tsnc.hypernetwork"12 13 14def package_installed() -> bool:15 try:16 return importlib.util.find_spec(PACKAGE) is not None17 except ModuleNotFoundError:18 return False19 20 21def install_private_package() -> None:22 if package_installed():23 print(f"{PACKAGE} already installed.")24 return25 26 token = os.environ.get("GITHUB_TOKEN")27 if not token:28 raise RuntimeError(29 "GITHUB_TOKEN Space secret is required to install "30 f"{GITHUB_REPO}. Create a GitHub classic PAT with repo scope."31 )32 33 url = f"git+https://x-access-token:{token}@github.com/{GITHUB_REPO}.git"34 print(f"Installing {GITHUB_REPO} from private GitHub...")35 subprocess.check_call(36 [sys.executable, "-m", "pip", "install", "--no-cache-dir", url],37 )38 print(f"Installed {PACKAGE}.")39 40 41if __name__ == "__main__":42 install_private_package()43 