ehejin commited on
Commit
350ec72
·
1 Parent(s): 2984dc5

fix shutree error

Browse files
Files changed (1) hide show
  1. 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
- result = subprocess.run(
38
- [
39
- "git", "clone",
40
- "--branch", "0412_train",
41
- "--depth", "1",
42
- f"https://ehejin:{token}@github.com/batu-el/lsp.git",
43
- str(_LSP_PATH),
44
- ],
45
- capture_output=True, text=True,
46
- )
47
- print(f"[SUBMODULE] clone stdout: {result.stdout}")
48
- print(f"[SUBMODULE] clone stderr: {result.stderr}")
49
- print(f"[SUBMODULE] clone returncode: {result.returncode}")
50
- print(f"[SUBMODULE] prompts exists after clone: {(_LSP_PATH / 'src' / 'prompts').exists()}")
51
- if result.returncode != 0:
52
- raise RuntimeError(f"Failed to clone lsp: {result.stderr}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: