-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprism.py
More file actions
67 lines (52 loc) · 2.11 KB
/
prism.py
File metadata and controls
67 lines (52 loc) · 2.11 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
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
def find_project_root():
"""Find the project root directory (contains app/ and .venv/)."""
# Start from script location
current = Path(__file__).resolve().parent
# If we're in .venv/bin/, go up two levels
if current.name == "bin" and current.parent.name == ".venv":
return current.parent.parent
# Otherwise, current directory should be the project root
return current
# Check if we're in the correct virtual environment
def check_and_activate_venv():
"""Check if the correct venv is activated, if not try to re-execute with it."""
# Skip check if explicitly requested or in CI environment
if os.environ.get("PRISM_SKIP_VENV_CHECK") or os.environ.get("CI"):
return
project_root = find_project_root()
venv_dir = project_root / ".venv"
# Check if venv exists
if not venv_dir.exists():
print(f"Warning: Virtual environment not found at {venv_dir}")
print("Run setup.sh or setup.ps1 to create it.")
return
# Determine venv python path
if sys.platform == "win32":
venv_python = venv_dir / "Scripts" / "python.exe"
else:
venv_python = venv_dir / "bin" / "python"
# Check if we're already running from the venv
if sys.executable == str(venv_python) or sys.prefix == str(venv_dir):
return # Already in venv
# Check if venv python exists
if not venv_python.exists():
print(f"Warning: Virtual environment Python not found at {venv_python}")
return
# Re-execute with venv python
print(f"⚠️ Activating virtual environment: {venv_dir}")
os.execv(str(venv_python), [str(venv_python)] + sys.argv)
# Check venv before doing anything else
check_and_activate_venv()
# Redirect to the consolidated app folder
if __name__ == "__main__":
project_root = find_project_root()
app_script = project_root / "app" / "prism.py"
if app_script.exists():
os.execv(sys.executable, [sys.executable, str(app_script)] + sys.argv[1:])
else:
print(f"Error: {app_script} not found.")
sys.exit(1)