Spaces:
Sleeping
Sleeping
| """Install private GitHub dependencies at runtime (HF build secrets are unreliable for pip git URLs).""" | |
| from __future__ import annotations | |
| import importlib.util | |
| import os | |
| import subprocess | |
| import sys | |
| GITHUB_REPO = "belcour/egsr2026_hypernetwork" | |
| PACKAGE = "tsnc.hypernetwork" | |
| def package_installed() -> bool: | |
| try: | |
| return importlib.util.find_spec(PACKAGE) is not None | |
| except ModuleNotFoundError: | |
| return False | |
| def install_private_package() -> None: | |
| if package_installed(): | |
| print(f"{PACKAGE} already installed.") | |
| return | |
| token = os.environ.get("GITHUB_TOKEN") | |
| if not token: | |
| raise RuntimeError( | |
| "GITHUB_TOKEN Space secret is required to install " | |
| f"{GITHUB_REPO}. Create a GitHub classic PAT with repo scope." | |
| ) | |
| url = f"git+https://x-access-token:{token}@github.com/{GITHUB_REPO}.git" | |
| print(f"Installing {GITHUB_REPO} from private GitHub...") | |
| subprocess.check_call( | |
| [sys.executable, "-m", "pip", "install", "--no-cache-dir", url], | |
| ) | |
| print(f"Installed {PACKAGE}.") | |
| if __name__ == "__main__": | |
| install_private_package() | |