-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
43 lines (36 loc) · 1.3 KB
/
Copy pathlauncher.py
File metadata and controls
43 lines (36 loc) · 1.3 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
"""
TechScript launcher module.
Used to forward `tsc` commands when invoked through `python -m techscript run`.
"""
import os
import shutil
import subprocess
import sys
def find_tsc() -> str:
"""Find the tsc binary or raise an error."""
tsc = shutil.which("tsc")
if not tsc:
# Also check the default install locations explicitly
candidates = []
local_app = os.environ.get("LOCALAPPDATA", "")
if local_app:
candidates.append(os.path.join(local_app, "TechScript", "bin", "tsc.exe"))
candidates.append(os.path.expanduser("~/.local/bin/tsc"))
prefix = os.environ.get("PREFIX", "")
if prefix:
candidates.append(os.path.join(prefix, "bin", "tsc"))
for path in candidates:
if os.path.isfile(path) and os.access(path, os.X_OK):
return path
print("\n ✘ TechScript compiler (tsc) is not installed or not found in PATH.", file=sys.stderr)
print(" Run: techscript install", file=sys.stderr)
sys.exit(1)
return tsc
def launch(args: list) -> int:
"""Forward args to the tsc binary and return the exit code."""
tsc = find_tsc()
try:
result = subprocess.run([tsc] + args)
return result.returncode
except KeyboardInterrupt:
return 130