-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbootstrap.py
More file actions
51 lines (45 loc) · 1.46 KB
/
bootstrap.py
File metadata and controls
51 lines (45 loc) · 1.46 KB
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
import shutil
import os
import subprocess
import sys
def find_pnpm():
"""
Cross-platform pnpm resolver.
Returns the absolute path to pnpm or pnpm.cmd.
"""
# 1. Try PATH first (works on macOS/Linux, sometimes on Windows)
pnpm_path = shutil.which("pnpm")
if pnpm_path:
return pnpm_path
# 2. Windows-specific fallback: check AppData global npm path
if os.name == "nt":
user = os.environ.get("USERPROFILE") or os.environ.get("HOMEPATH")
if user:
candidate = os.path.join(user, "AppData", "Roaming", "npm", "pnpm.cmd")
if os.path.exists(candidate):
return candidate
# 3. Check Program Files (Corepack shim location)
corepack_candidate = r"C:\Program Files\nodejs\pnpm.cmd"
if os.path.exists(corepack_candidate):
return corepack_candidate
# 4. If still not found, fail with a clean message
raise FileNotFoundError(
"pnpm not found. Ensure Corepack is enabled or pnpm is installed globally."
)
def run_command(cmd, check=True):
"""
Wrapper around subprocess.run with clean error handling.
"""
try:
result = subprocess.run(
cmd,
shell=False,
check=check,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return result
except FileNotFoundError as e:
print(f"✗ Command not found: {cmd[0]}")
raise e