File size: 3,882 Bytes
93a3c54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 alvations (Melon Lab)
"""Deploy a NON-CANONICAL *shortcut* build of the game for quick testing.

This is exactly the same game as `scripts/deploy_hf.py` ships, but the win is
reached in **3 stages instead of 8**, so you can get to the end screen (the
look-back line and the share block) in a few calls instead of a full run. It is
for testing only and must not be treated as the real game.

How it works: the goal is read from the `H8_GOAL` environment variable at
startup (see `hallway.py`, clamped to 1..8). This script uploads the repo to a
separate Space and sets that Space's `H8_GOAL` variable to 3. It also sets
`H8_ACT2_TEST=1`, which boosts the Act 2 triggers so the folds and the alternate
endings can actually be reached in a short test session (in the real game they
are rare by design). The code is identical; only the target and these env vars
differ.

Run from a machine with normal internet access (not the sandboxed web session,
whose network policy blocks huggingface.co):

    pip install "huggingface_hub>=0.24"
    export HF_TOKEN=hf_...                 # a *write* token
    python scripts/deploy_hf_shortcut.py   # -> alvations/hallway8-shortcut, 3 stages

Optionally pass a different target or stage count:
    python scripts/deploy_hf_shortcut.py owner/space-name 3

Locally you can get the same shortcut without deploying:
    H8_GOAL=3 python app.py
"""

import os
import secrets
import sys

from huggingface_hub import HfApi, get_token

REPO_ID = sys.argv[1] if len(sys.argv) > 1 else "alvations/hallway8-shortcut"
GOAL = sys.argv[2] if len(sys.argv) > 2 else "3"
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def main() -> None:
    if REPO_ID.endswith("/hallway8"):
        sys.exit("Refusing to overwrite the canonical Space; pick a different id.")

    token = os.environ.get("HF_TOKEN") or get_token()
    if not token:
        sys.exit(
            "No token found. Run `hf auth login` or set HF_TOKEN to a write token."
        )

    api = HfApi(token=token)
    who = api.whoami()
    print(f"Authenticated as {who['name']}")
    print(f"SHORTCUT (non-canonical) build: {REPO_ID}, goal = {GOAL} stages")

    url = api.create_repo(
        repo_id=REPO_ID, repo_type="space", space_sdk="docker", exist_ok=True
    )
    print(f"Space ready: {url}")

    # The one thing that makes this a shortcut: fewer stages, via env var.
    try:
        api.add_space_variable(REPO_ID, "H8_GOAL", str(GOAL))
        print(f"H8_GOAL variable set to {GOAL}")
    except Exception as exc:
        sys.exit(f"Could not set H8_GOAL (shortcut would not apply): {exc}")

    # Boost the Act 2 triggers so the folds and the alternate endings can be
    # reached quickly for testing. This flag is NOT set on the real deploy.
    try:
        api.add_space_variable(REPO_ID, "H8_ACT2_TEST", "1")
        print("H8_ACT2_TEST variable set to 1 (Act 2 endings easy to reach)")
    except Exception as exc:
        print(f"Could not set H8_ACT2_TEST: {exc}")

    # Stable session key so in-progress runs survive Space restarts.
    try:
        api.add_space_secret(REPO_ID, "SECRET_KEY", secrets.token_hex(32))
        print("SECRET_KEY secret set")
    except Exception as exc:  # non-fatal
        print(f"Could not set SECRET_KEY (set it manually if you want): {exc}")

    api.upload_folder(
        folder_path=ROOT,
        repo_id=REPO_ID,
        repo_type="space",
        commit_message=f"Deploy shortcut test build ({GOAL} stages, non-canonical)",
        ignore_patterns=[
            ".git*", "**/__pycache__/**", "*.pyc", ".venv/**", "venv/**", ".env",
        ],
    )
    print(f"\nDone -> https://huggingface.co/spaces/{REPO_ID}")
    print(f"Reaches the end screen in {GOAL} correct calls. Test-only build.")


if __name__ == "__main__":
    main()