HomePilot Deploy Bot commited on
Commit
0639cbc
·
1 Parent(s): 66c5a2b

chore: sync installer from monorepo

Browse files
Files changed (1) hide show
  1. server.py +47 -2
server.py CHANGED
@@ -93,8 +93,53 @@ async def install(request: Request):
93
  remote = f"https://user:{token}@huggingface.co/spaces/{repo_id}"
94
  tpl_remote = f"https://user:{token}@huggingface.co/spaces/{TEMPLATE}"
95
 
96
- subprocess.run(["git", "-c", "credential.helper=", "clone", "--depth", "1",
97
- tpl_remote, f"{tmp}/tpl"], capture_output=True, timeout=60)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  clone = subprocess.run(["git", "-c", "credential.helper=", "clone", "--depth", "1",
100
  remote, f"{tmp}/sp"], capture_output=True, timeout=30)
 
93
  remote = f"https://user:{token}@huggingface.co/spaces/{repo_id}"
94
  tpl_remote = f"https://user:{token}@huggingface.co/spaces/{TEMPLATE}"
95
 
96
+ # Clone the template Space (preferred) OR fall back to the public
97
+ # GitHub source. HF Spaces 404 until ``sync-hf-spaces.yml`` has
98
+ # successfully run at least once; in that window the installer
99
+ # would previously silently fail later when the staged tpl/
100
+ # directory didn't exist, producing the cryptic
101
+ # "[Errno 2] No such file or directory: '/tmp/.../tpl'"
102
+ tpl_path = Path(f"{tmp}/tpl")
103
+ tpl_source = None
104
+ tpl_clone = subprocess.run(
105
+ ["git", "-c", "credential.helper=", "clone", "--depth", "1",
106
+ tpl_remote, str(tpl_path)],
107
+ capture_output=True, timeout=60,
108
+ )
109
+ if tpl_clone.returncode == 0 and tpl_path.exists():
110
+ tpl_source = f"spaces/{TEMPLATE}"
111
+ else:
112
+ # Fallback: clone HomePilot from GitHub master.
113
+ gh_fallback = os.environ.get(
114
+ "TEMPLATE_GITHUB",
115
+ f"https://github.com/{TEMPLATE}.git",
116
+ )
117
+ fb = subprocess.run(
118
+ ["git", "clone", "--depth", "1", gh_fallback, str(tpl_path)],
119
+ capture_output=True, timeout=120,
120
+ )
121
+ if fb.returncode == 0 and tpl_path.exists():
122
+ tpl_source = f"github.com/{TEMPLATE} (fallback)"
123
+ else:
124
+ tpl_err = (
125
+ tpl_clone.stderr or tpl_clone.stdout or b""
126
+ ).decode("utf-8", errors="replace")[:300]
127
+ fb_err = (
128
+ fb.stderr or fb.stdout or b""
129
+ ).decode("utf-8", errors="replace")[:300]
130
+ return JSONResponse({
131
+ "ok": False,
132
+ "error": (
133
+ "HomePilot template is not yet available. The "
134
+ "sync-hf-spaces.yml workflow must publish the "
135
+ f"template Space at {TEMPLATE} first.\n"
136
+ f"HF clone: {tpl_err.strip() or '<empty>'}\n"
137
+ f"GH clone: {fb_err.strip() or '<empty>'}"
138
+ ),
139
+ "steps": steps,
140
+ })
141
+
142
+ steps.append(f"Template: {tpl_source}")
143
 
144
  clone = subprocess.run(["git", "-c", "credential.helper=", "clone", "--depth", "1",
145
  remote, f"{tmp}/sp"], capture_output=True, timeout=30)