Spaces:
Sleeping
Sleeping
fix shutree error
Browse files- src/app.py +39 -17
src/app.py
CHANGED
|
@@ -31,25 +31,47 @@ def _init_submodule() -> None:
|
|
| 31 |
token = os.getenv("GH_TOKEN", "")
|
| 32 |
if not token:
|
| 33 |
raise RuntimeError("GH_TOKEN secret is not set.")
|
|
|
|
| 34 |
import shutil
|
|
|
|
|
|
|
| 35 |
if _LSP_PATH.exists():
|
| 36 |
-
shutil.rmtree(str(_LSP_PATH))
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
lsp_src = str(_LSP_PATH / "src")
|
| 55 |
if lsp_src not in sys.path:
|
|
|
|
| 31 |
token = os.getenv("GH_TOKEN", "")
|
| 32 |
if not token:
|
| 33 |
raise RuntimeError("GH_TOKEN secret is not set.")
|
| 34 |
+
|
| 35 |
import shutil
|
| 36 |
+
|
| 37 |
+
# Aggressively remove any partial/corrupt lsp directory
|
| 38 |
if _LSP_PATH.exists():
|
| 39 |
+
shutil.rmtree(str(_LSP_PATH), ignore_errors=True)
|
| 40 |
+
# Also nuke any leftover .git/modules/lsp entry
|
| 41 |
+
git_modules = _BASE / ".git" / "modules" / "lsp"
|
| 42 |
+
if git_modules.exists():
|
| 43 |
+
shutil.rmtree(str(git_modules), ignore_errors=True)
|
| 44 |
+
|
| 45 |
+
clone_url = f"https://ehejin:{token}@github.com/batu-el/lsp.git"
|
| 46 |
+
|
| 47 |
+
for attempt in range(1, 4):
|
| 48 |
+
print(f"[SUBMODULE] clone attempt {attempt}/3 ...")
|
| 49 |
+
# Remove any partial clone from previous attempt
|
| 50 |
+
if _LSP_PATH.exists():
|
| 51 |
+
shutil.rmtree(str(_LSP_PATH), ignore_errors=True)
|
| 52 |
+
result = subprocess.run(
|
| 53 |
+
[
|
| 54 |
+
"git", "clone",
|
| 55 |
+
"--branch", "0412_train",
|
| 56 |
+
"--depth", "1",
|
| 57 |
+
clone_url,
|
| 58 |
+
str(_LSP_PATH),
|
| 59 |
+
],
|
| 60 |
+
capture_output=True, text=True,
|
| 61 |
+
)
|
| 62 |
+
print(f"[SUBMODULE] returncode: {result.returncode}")
|
| 63 |
+
if result.stderr:
|
| 64 |
+
# Scrub token from log
|
| 65 |
+
print(f"[SUBMODULE] stderr: {result.stderr.replace(token, '***')}")
|
| 66 |
+
if result.returncode == 0 and (_LSP_PATH / "src" / "prompts").exists():
|
| 67 |
+
print("[SUBMODULE] clone succeeded.")
|
| 68 |
+
break
|
| 69 |
+
print(f"[SUBMODULE] attempt {attempt} failed, retrying...")
|
| 70 |
+
else:
|
| 71 |
+
raise RuntimeError(
|
| 72 |
+
f"Failed to clone lsp after 3 attempts. "
|
| 73 |
+
f"Last stderr: {result.stderr.replace(token, '***')}"
|
| 74 |
+
)
|
| 75 |
|
| 76 |
lsp_src = str(_LSP_PATH / "src")
|
| 77 |
if lsp_src not in sys.path:
|