-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotespacellm_launcher.py
More file actions
67 lines (52 loc) · 1.66 KB
/
Copy pathnotespacellm_launcher.py
File metadata and controls
67 lines (52 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import annotations
import ctypes
from pathlib import Path
import shutil
import subprocess
import sys
APP_NAME = "NoteSpaceLLM"
SCRIPT_NAME = "main.py"
def _project_dir() -> Path:
if getattr(sys, "frozen", False):
return Path(sys.executable).resolve().parent
return Path(__file__).resolve().parent
def _show_error(message: str) -> None:
try:
ctypes.windll.user32.MessageBoxW(0, message, APP_NAME, 0x10)
except Exception:
print(message, file=sys.stderr)
def _python_command() -> list[str] | None:
for candidate in ("pythonw.exe", "python.exe"):
resolved = shutil.which(candidate)
if resolved:
return [resolved]
launcher = shutil.which("py.exe") or shutil.which("py")
if launcher:
return [launcher, "-3"]
return None
def main() -> int:
base_dir = _project_dir()
app_script = base_dir / SCRIPT_NAME
if not app_script.exists():
_show_error(f"{SCRIPT_NAME} wurde nicht gefunden:\n{app_script}")
return 1
python_cmd = _python_command()
if not python_cmd:
_show_error(
"Python wurde nicht gefunden.\n"
"Bitte Python 3.10+ installieren und die Abhängigkeiten aus requirements.txt einrichten."
)
return 1
creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
try:
subprocess.Popen(
python_cmd + [str(app_script)],
cwd=str(base_dir),
creationflags=creationflags,
)
except FileNotFoundError as exc:
_show_error(f"Start fehlgeschlagen:\n{exc}")
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())