Spaces:
Runtime error
Runtime error
| import os | |
| import subprocess | |
| import sys | |
| GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") | |
| REPO_NAME = os.environ.get("REPO_NAME") | |
| BRANCH = "main" | |
| def try_install_cpg_base(): | |
| """Try installing the repo via pip, but never leak the token in errors.""" | |
| if not GITHUB_TOKEN: | |
| return | |
| url = f"git+https://{GITHUB_TOKEN}@github.com/{REPO_NAME}.git@{BRANCH}" | |
| try: | |
| subprocess.check_call( | |
| [sys.executable, "-m", "pip", "install", url] | |
| ) | |
| except subprocess.CalledProcessError as e: | |
| print( | |
| f"[WARNING] pip install failed - ERROR " | |
| f"with return code {e.returncode}.", | |
| file=sys.stderr, | |
| ) | |
| try: | |
| from myapp.app import start_app | |
| except ModuleNotFoundError: | |
| try_install_cpg_base() | |
| from myapp.app import start_app | |
| start_app() | |