-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·347 lines (293 loc) · 10.8 KB
/
run.py
File metadata and controls
executable file
·347 lines (293 loc) · 10.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env python3
"""
Time Warp Studio Launcher
========================
Intelligent launcher that:
1. Checks for virtual environment (.venv)
2. Creates one if needed
3. Installs/upgrades dependencies
4. Executes Time Warp Studio IDE
Usage:
python run.py # Run normally
python run.py --fresh # Force fresh venv
python run.py --skip-setup # Skip dependency check
python run.py --help # Show help
"""
import sys
import subprocess
import argparse
import os
from pathlib import Path
# Configuration
PROJECT_ROOT = Path(__file__).parent.absolute()
VENV_DIR = PROJECT_ROOT / ".venv"
PYTHON_EXECUTABLE = sys.executable
IDE_SCRIPT = PROJECT_ROOT / "Platforms" / "Python" / "time_warp_ide.py"
REQUIREMENTS_FILE = PROJECT_ROOT / "Platforms" / "Python" / "requirements.txt"
# ANSI Colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
GREEN = "\033[92m"
BLUE = "\033[94m"
YELLOW = "\033[93m"
RED = "\033[91m"
def print_header(text: str) -> None:
"""Print formatted header"""
print(f"\n{Colors.BOLD}{Colors.BLUE}{'='*60}{Colors.RESET}")
print(f"{Colors.BOLD}{Colors.BLUE}{text}{Colors.RESET}")
print(f"{Colors.BOLD}{Colors.BLUE}{'='*60}{Colors.RESET}\n")
def print_success(text: str) -> None:
"""Print success message"""
print(f"{Colors.GREEN}✅ {text}{Colors.RESET}")
def print_info(text: str) -> None:
"""Print info message"""
print(f"{Colors.BLUE}ℹ️ {text}{Colors.RESET}")
def print_warning(text: str) -> None:
"""Print warning message"""
print(f"{Colors.YELLOW}⚠️ {text}{Colors.RESET}")
def print_error(text: str) -> None:
"""Print error message"""
print(f"{Colors.RED}❌ {text}{Colors.RESET}")
def check_python_version() -> bool:
"""Check if Python version is 3.10+"""
if sys.version_info < (3, 10):
print_error(
f"Python 3.10+ required (you have {sys.version_info.major}.{sys.version_info.minor})"
)
return False
print_success(
f"Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
)
return True
def create_venv() -> bool:
"""Create virtual environment"""
print_info(f"Creating virtual environment: {VENV_DIR}")
try:
subprocess.run(
[PYTHON_EXECUTABLE, "-m", "venv", str(VENV_DIR)],
check=True,
capture_output=True,
timeout=60,
)
print_success("Virtual environment created")
return True
except subprocess.CalledProcessError as e:
print_error(f"Failed to create venv: {e.stderr.decode()}")
return False
except subprocess.TimeoutExpired:
print_error("Virtual environment creation timed out")
return False
def get_venv_python() -> Path:
"""Get path to Python executable in venv"""
if sys.platform == "win32":
return VENV_DIR / "Scripts" / "python.exe"
return VENV_DIR / "bin" / "python"
def upgrade_pip(venv_python: Path) -> bool:
"""Upgrade pip in virtual environment"""
print_info("Upgrading pip...")
try:
subprocess.run(
[
str(venv_python),
"-m",
"pip",
"install",
"--upgrade",
"pip",
"setuptools",
"wheel",
],
check=True,
capture_output=True,
timeout=120,
)
print_success("pip upgraded")
return True
except subprocess.CalledProcessError:
print_warning("pip upgrade had issues, continuing anyway...")
return True
except subprocess.TimeoutExpired:
print_warning("pip upgrade timed out, continuing anyway...")
return True
def install_dependencies(venv_python: Path) -> bool:
"""Install project dependencies"""
if not REQUIREMENTS_FILE.exists():
print_warning(f"Requirements file not found: {REQUIREMENTS_FILE}")
return False
print_info(f"Installing dependencies from {REQUIREMENTS_FILE.name}...")
try:
subprocess.run(
[str(venv_python), "-m", "pip", "install", "-r", str(REQUIREMENTS_FILE)],
check=True,
timeout=300,
)
print_success("Dependencies installed")
return True
except subprocess.CalledProcessError as e:
print_error(f"Failed to install dependencies: {e}")
return False
except subprocess.TimeoutExpired:
print_error("Dependency installation timed out")
return False
def verify_ide_script() -> bool:
"""Verify IDE script exists"""
if not IDE_SCRIPT.exists():
print_error(f"IDE script not found: {IDE_SCRIPT}")
return False
print_success(f"IDE script found: {IDE_SCRIPT.name}")
return True
def run_ide(venv_python: Path) -> bool:
"""Execute the IDE"""
print_header("🚀 Launching Time Warp Studio")
if not IDE_SCRIPT.exists():
print_error(f"IDE script not found: {IDE_SCRIPT}")
return False
env = os.environ.copy()
existing_rules = env.get("QT_LOGGING_RULES", "").strip()
required_rules = {
"qt.svg.warning": "false",
"qt.qpa.theme.gnome.warning": "false",
}
parsed_rules = {}
if existing_rules:
for part in existing_rules.split(";"):
item = part.strip()
if not item or "=" not in item:
continue
key, value = item.split("=", 1)
parsed_rules[key.strip()] = value.strip()
for key, value in required_rules.items():
parsed_rules.setdefault(key, value)
env["QT_LOGGING_RULES"] = ";".join(
f"{key}={value}" for key, value in parsed_rules.items()
)
# Prefer the native platform plugin; fall back to xcb if Wayland is
# unavailable so the launcher doesn't silently get SIGKILL'd by the
# compositor when there is no active Wayland session.
if "QT_QPA_PLATFORM" not in env:
if env.get("WAYLAND_DISPLAY"):
env["QT_QPA_PLATFORM"] = "wayland;xcb"
elif env.get("DISPLAY"):
env["QT_QPA_PLATFORM"] = "xcb"
try:
# Run IDE in venv — don't use check=True so we can inspect the
# returncode and signal ourselves and give a useful message.
result = subprocess.run(
[str(venv_python), str(IDE_SCRIPT)],
cwd=str(PROJECT_ROOT),
env=env,
)
rc = result.returncode
if rc == 0:
return True
# Negative returncode means the process was killed by a signal
if rc < 0:
import signal as _signal
try:
sig = _signal.Signals(-rc)
if sig == _signal.SIGKILL:
print_error(
"IDE was force-killed (SIGKILL). "
"This is usually caused by the system OOM killer "
"running out of memory, or the Wayland/X compositor "
"terminating an unresponsive client. "
"Try closing other applications and running again."
)
elif sig == _signal.SIGSEGV:
print_error(
"IDE crashed with a segmentation fault (SIGSEGV). "
"This may be a PySide6/Qt driver issue. "
"Try: QT_QPA_PLATFORM=xcb ./run.sh"
)
elif sig == _signal.SIGILL:
print_error(
"IDE crashed due to an illegal CPU instruction (SIGILL). "
"PySide6 6.x requires SSSE3/SSE4.1/SSE4.2/POPCNT. "
"Your CPU or VM may not support these instructions."
)
else:
print_error(f"IDE terminated by signal {sig.name} ({-rc})")
except ValueError:
print_error(f"IDE terminated by unknown signal {-rc}")
return False
print_error(f"IDE exited with code {rc}")
return False
except KeyboardInterrupt:
print_info("\nIDE closed by user")
return True
except Exception as e: # noqa: BLE001 # pylint: disable=broad-exception-caught
print_error(f"Failed to run IDE: {e}")
return False
def main():
"""Main entry point"""
parser = argparse.ArgumentParser(
description="Time Warp Studio Launcher",
epilog="https://github.com/James-HoneyBadger/Time_Warp_Studio",
)
parser.add_argument(
"--fresh", action="store_true", help="Delete and recreate virtual environment"
)
parser.add_argument(
"--skip-setup",
action="store_true",
help="Skip dependency installation (assume venv is ready)",
)
parser.add_argument(
"--no-venv",
action="store_true",
help="Run with system Python (not recommended)",
)
args = parser.parse_args()
print_header("⏰ Time Warp Studio Launcher")
# Step 1: Check Python version
print_info("Checking Python version...")
if not check_python_version():
print_error("Please install Python 3.10 or higher")
sys.exit(1)
# Step 2: Handle virtual environment
venv_python = get_venv_python()
if args.no_venv:
print_warning("Running with system Python (not recommended)")
venv_python = Path(PYTHON_EXECUTABLE)
else:
# Delete venv if --fresh requested
if args.fresh and VENV_DIR.exists():
print_info("Removing existing virtual environment...")
subprocess.run(["rm", "-rf", str(VENV_DIR)], check=True)
print_success("Virtual environment removed")
# Create venv if needed
if not VENV_DIR.exists():
print_info("Virtual environment not found")
if not create_venv():
sys.exit(1)
else:
print_success(f"Virtual environment found: {VENV_DIR.name}/")
# Step 3: Install dependencies
if not args.skip_setup:
print_header("📦 Setting up dependencies")
if not upgrade_pip(venv_python):
print_warning("pip upgrade failed, continuing...")
if not install_dependencies(venv_python):
print_error("Failed to install dependencies")
sys.exit(1)
else:
print_info("Skipping dependency check (--skip-setup)")
# Step 4: Verify IDE script exists
print_header("🔍 Verifying installation")
if not verify_ide_script():
sys.exit(1)
# Step 5: Run IDE
if not run_ide(venv_python):
sys.exit(1)
print_header("👋 Thank you for using Time Warp Studio!")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(f"\n{Colors.YELLOW}Launcher interrupted by user{Colors.RESET}")
sys.exit(0)
except Exception as e: # noqa: BLE001 # pylint: disable=broad-exception-caught
print_error(f"Unexpected error: {e}")
sys.exit(1)