contimp-app / scripts /deploy.py
lefft's picture
Per-task LLM backends (OpenAI + Anthropic wire); config-copilot pinned to the oumi backend
1bcb9d8 verified
Raw
History Blame Contribute Delete
2.91 kB
"""Deploy the current working tree to the Hugging Face Space.
The Space (https://huggingface.co/spaces/lefft/contimp-app) builds from its own
copy of these files. This uploads the repo's working tree to the Space, which
triggers a rebuild. Merging to GitHub does NOT deploy β€” this is the deploy step.
Run after merging a change to main, from anywhere in the repo:
uv run --with huggingface_hub python scripts/deploy.py -m "what changed"
Auth: uses your cached Hugging Face login (run `hf auth login` once; token lives
in ~/.cache/huggingface/). You must have write access to the Space. No app
secrets are involved here β€” those live in the Space's own Settings, never in
this repo. `.env` and other local-only files are excluded from the upload.
"""
import argparse
import sys
from pathlib import Path
SPACE_ID = "lefft/contimp-app"
REPO_ROOT = Path(__file__).resolve().parent.parent
# Everything that must never reach the Space (secrets, local env, caches, VCS,
# and Claude Code tooling β€” skills/settings/worktrees are dev-only and the Space
# does not need them; this also keeps stray git worktrees out of the upload).
IGNORE = [
".git/*", ".git*", ".venv/*", "__pycache__/*", "**/__pycache__/*",
"*.pyc", ".env", ".env.*", ".pytest_cache/*",
".claude/*", ".claude",
"docs/internal/*", # internal design docs β€” never publish to the Space
]
def main() -> None:
parser = argparse.ArgumentParser(description="Deploy working tree to the HF Space.")
parser.add_argument("-m", "--message", default="Manual deploy from working tree",
help="Commit message for the Space upload")
args = parser.parse_args()
# Guard against uploading the wrong directory.
if not (REPO_ROOT / "pyproject.toml").exists() or not (REPO_ROOT / "app").is_dir():
sys.exit(f"refusing to deploy: {REPO_ROOT} doesn't look like the contimp-app repo")
try:
from huggingface_hub import HfApi
except ImportError:
sys.exit("huggingface_hub not installed. Run via: "
"uv run --with huggingface_hub python scripts/deploy.py")
api = HfApi()
try:
who = api.whoami()
except Exception:
sys.exit("not logged in to Hugging Face. Run `hf auth login` first "
"(needs write access to the Space).")
print(f"deploying {REPO_ROOT.name} as {who['name']} -> {SPACE_ID}")
api.upload_folder(
folder_path=str(REPO_ROOT),
repo_id=SPACE_ID,
repo_type="space",
commit_message=args.message,
ignore_patterns=IGNORE,
)
print("uploaded; the Space is rebuilding (~1-2 min).")
print(" app: https://lefft-contimp-app.hf.space")
print(" verify: curl https://lefft-contimp-app.hf.space/api/health")
print(" logs: https://huggingface.co/spaces/lefft/contimp-app (Settings -> Logs)")
if __name__ == "__main__":
main()