-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·278 lines (213 loc) · 8.12 KB
/
run.py
File metadata and controls
executable file
·278 lines (213 loc) · 8.12 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
#!/usr/bin/env python3
"""
Time Warp II - Complete Setup & Run Script (Cross-Platform)
This script:
1. Creates a Python virtual environment (if needed)
2. Installs all required Python dependencies
3. Launches the Time Warp II GUI
Usage:
python3 run.py # Normal startup with dependency installation
python3 run.py --clean # Delete and recreate virtual environment
python3 run.py --no-install # Skip dependency installation
python3 run.py --help # Show this help message
Copyright © 2025 Honey Badger Universe
"""
import os
import sys
import subprocess
import argparse
import platform
from pathlib import Path
# Colors for console output
class Colors:
"""ANSI color codes for terminal output"""
BLUE = '\033[0;34m'
GREEN = '\033[0;32m'
YELLOW = '\033[1;33m'
RED = '\033[0;31m'
END = '\033[0m'
@staticmethod
def disable_on_windows():
"""Disable colors on Windows if not supported"""
if platform.system() == 'Windows':
Colors.BLUE = Colors.GREEN = Colors.YELLOW = Colors.RED = Colors.END = ''
# Disable colors if needed
Colors.disable_on_windows()
def print_header(title):
"""Print a formatted header"""
print(f"\n{Colors.BLUE}{'='*60}{Colors.END}")
print(f"{Colors.BLUE}{title:^60}{Colors.END}")
print(f"{Colors.BLUE}{'='*60}{Colors.END}\n")
def print_step(number, title):
"""Print a step header"""
print(f"{Colors.YELLOW}[{number}/4]{Colors.END} {title}...")
def print_success(message):
"""Print a success message"""
print(f"{Colors.GREEN}✓{Colors.END} {message}")
def print_warning(message):
"""Print a warning message"""
print(f"{Colors.YELLOW}⚠{Colors.END} {message}")
def print_error(message):
"""Print an error message"""
print(f"{Colors.RED}✗{Colors.END} {message}")
def run_command(cmd, capture_output=False, check=True):
"""Run a shell command"""
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=capture_output,
text=True,
check=False
)
if check and result.returncode != 0:
return False
return result
except Exception as e:
print_error(f"Failed to run command: {e}")
return False
def check_python():
"""Check Python version"""
print_step(1, "Checking Python installation")
version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
print_success(f"Python {version} found\n")
if sys.version_info < (3, 9):
print_error("Python 3.9 or higher is required")
return False
return True
def setup_venv(venv_path, clean=False):
"""Setup virtual environment"""
print_step(2, "Setting up Virtual Environment")
if clean and venv_path.exists():
print("🗑️ Removing existing virtual environment...")
import shutil
shutil.rmtree(venv_path)
if not venv_path.exists():
print("📦 Creating virtual environment...")
result = run_command(f"{sys.executable} -m venv {venv_path}", check=True)
if not result:
print_error("Failed to create virtual environment")
return False
print_success("Virtual environment created")
else:
print_success("Virtual environment already exists")
print()
return True
def get_python_exe(venv_path):
"""Get the Python executable in the venv"""
if platform.system() == 'Windows':
return str(venv_path / 'Scripts' / 'python.exe')
return str(venv_path / 'bin' / 'python')
def install_dependencies(venv_path, no_install=False):
"""Install Python dependencies"""
if no_install:
print_step(3, "Skipping dependency installation")
print("(--no-install flag set)\n")
return True
print_step(3, "Installing Python dependencies")
python_exe = get_python_exe(venv_path)
# Check if requirements.txt exists
req_file = Path('requirements.txt')
if not req_file.exists():
print_error("requirements.txt not found!")
return False
# Upgrade pip
print("📥 Upgrading pip...")
run_command(f"{python_exe} -m pip install --upgrade pip setuptools wheel")
# Install requirements
print("📚 Installing packages from requirements.txt...")
result = run_command(f"{python_exe} -m pip install -r {req_file}")
if result and result.returncode == 0:
print_success("All dependencies installed successfully")
else:
print_warning("Some dependencies may have failed to install")
print(" (This is often OK - many features work without optional dependencies)")
print()
return True
def verify_installation(venv_path):
"""Verify required and optional dependencies"""
print_step(4, "Verifying installation")
python_exe = get_python_exe(venv_path)
# Check tkinter (required)
result = run_command(f"{python_exe} -c 'import tkinter'", capture_output=True)
if result.returncode == 0:
print_success("tkinter available")
else:
print_error("tkinter not available!")
print(" This is required. If missing after installation, try:")
if platform.system() == 'Linux':
print(" Ubuntu/Debian: sudo apt-get install python3-tk")
print(" Fedora: sudo dnf install python3-tkinter")
elif platform.system() == 'Darwin':
print(" macOS: brew install python-tk")
# Check optional packages
packages = [
('pygame', 'pygame available (multimedia support)'),
('pygments', 'pygments available (syntax highlighting)'),
('PIL', 'PIL/Pillow available (image processing)'),
]
for pkg, msg in packages:
result = run_command(f"{python_exe} -c 'import {pkg}'", capture_output=True)
if result.returncode == 0:
print_success(msg)
else:
print_warning(f"{pkg} not available (optional feature)")
print()
return True
def launch_gui(venv_path):
"""Launch Time Warp II GUI"""
print_header("🚀 Launching Time Warp II...")
python_exe = get_python_exe(venv_path)
# Check if TimeWarpII.py exists
if not Path('TimeWarpII.py').exists():
print_error("TimeWarpII.py not found!")
return False
# Run the IDE
try:
subprocess.run([python_exe, 'TimeWarpII.py'], check=False)
return True
except Exception as e:
print_error(f"Failed to launch Time Warp II: {e}")
return False
def main():
"""Main entry point"""
parser = argparse.ArgumentParser(
description='Time Warp II - Setup & Launch Script',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
Examples:
python3 run.py # Normal startup
python3 run.py --clean # Recreate virtual environment
python3 run.py --no-install # Skip dependency installation
'''
)
parser.add_argument('--clean', action='store_true',
help='Delete and recreate the virtual environment')
parser.add_argument('--no-install', action='store_true',
help='Skip dependency installation')
args = parser.parse_args()
# Get paths
script_dir = Path(__file__).parent.absolute()
os.chdir(script_dir)
venv_path = script_dir / 'venv'
# Print header
print(f"\n{Colors.BLUE}╔{'='*58}╗{Colors.END}")
print(f"{Colors.BLUE}║ Time Warp II - TempleCode Language IDE{' '*15}║{Colors.END}")
print(f"{Colors.BLUE}║ Initialization & Setup Script{' '*28}║{Colors.END}")
print(f"{Colors.BLUE}╚{'='*58}╝{Colors.END}")
# Run steps
if not check_python():
return 1
if not setup_venv(venv_path, clean=args.clean):
return 1
if not install_dependencies(venv_path, no_install=args.no_install):
print_warning("Continuing despite installation issues...")
if not verify_installation(venv_path):
print_warning("Continuing despite verification issues...")
# Launch GUI
if not launch_gui(venv_path):
return 1
print(f"\n{Colors.BLUE}Goodbye from Time Warp II!{Colors.END}\n")
return 0
if __name__ == '__main__':
sys.exit(main())