-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlaunch_clean.py
More file actions
executable file
·140 lines (114 loc) · 4.34 KB
/
launch_clean.py
File metadata and controls
executable file
·140 lines (114 loc) · 4.34 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
#!/usr/bin/env python3
"""
Clean launcher for EvolDSL Frontend with port conflict handling
"""
import subprocess
import sys
import time
import webbrowser
import socket
from pathlib import Path
def is_port_available(port):
"""Check if a port is available"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind(('localhost', port))
return True
except OSError:
return False
def find_available_port(start_port, max_attempts=10):
"""Find an available port starting from start_port"""
for i in range(max_attempts):
port = start_port + i
if is_port_available(port):
return port
return None
def kill_processes_on_port(port):
"""Kill processes running on a specific port"""
try:
result = subprocess.run(['lsof', '-ti', f':{port}'],
capture_output=True, text=True)
if result.stdout.strip():
pids = result.stdout.strip().split('\n')
for pid in pids:
subprocess.run(['kill', '-9', pid], capture_output=True)
print(f"✅ Cleaned up processes on port {port}")
except Exception as e:
print(f"⚠️ Could not clean port {port}: {e}")
def main():
print("🧬 EvolDSL Professional Frontend - Clean Launch")
print("=" * 60)
# Clean up potential conflicts
print("🧹 Cleaning up any existing processes...")
kill_processes_on_port(3000)
kill_processes_on_port(8000)
time.sleep(2)
# Find available ports
backend_port = find_available_port(8000)
frontend_port = find_available_port(3000)
if not backend_port or not frontend_port:
print("❌ Could not find available ports. Please check your system.")
return
print(f"📡 Backend will use port: {backend_port}")
print(f"🎨 Frontend will use port: {frontend_port}")
# Update frontend to use correct backend port if different
if backend_port != 8000:
print(f"🔧 Updating frontend to use backend port {backend_port}...")
# We'll use environment variable for this
print("\n🚀 Starting EvolDSL...")
# Start backend
print(f"📡 Starting backend on http://localhost:{backend_port}...")
backend_env = dict(os.environ) if 'os' in globals() else {}
backend_env['PORT'] = str(backend_port)
backend_process = subprocess.Popen([
sys.executable, "backend_simple.py"
], env=backend_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for backend
time.sleep(4)
# Start frontend
print(f"🎨 Starting frontend on http://localhost:{frontend_port}...")
frontend_env = dict(os.environ) if 'os' in globals() else {}
frontend_env['PORT'] = str(frontend_port)
if backend_port != 8000:
frontend_env['VITE_API_URL'] = f'http://localhost:{backend_port}'
frontend_process = subprocess.Popen([
'npm', 'run', 'dev', '--', '--port', str(frontend_port)
], cwd='frontend', env=frontend_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for frontend
time.sleep(6)
print("\n🎉 EvolDSL is ready!")
print("=" * 60)
print(f"🌐 Frontend: http://localhost:{frontend_port}")
print(f"🔌 Backend: http://localhost:{backend_port}")
print("🔑 Your GPT-4o API key is pre-configured!")
print("💡 Click 'Start Evolution' to begin the demo")
print("=" * 60)
# Open browser
try:
webbrowser.open(f'http://localhost:{frontend_port}')
print("🌐 Opening browser...")
except Exception:
print("⚠️ Could not auto-open browser")
print("\n🛑 Press Enter to stop all servers...")
try:
input()
except KeyboardInterrupt:
pass
print("\n🛑 Stopping servers...")
# Stop processes
try:
backend_process.terminate()
frontend_process.terminate()
# Wait for graceful shutdown
backend_process.wait(timeout=5)
frontend_process.wait(timeout=5)
except subprocess.TimeoutExpired:
# Force kill if needed
backend_process.kill()
frontend_process.kill()
except Exception as e:
print(f"⚠️ Error stopping processes: {e}")
print("✅ All servers stopped. Thank you!")
if __name__ == "__main__":
import os
main()