-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_native.ps1
More file actions
114 lines (98 loc) · 4.51 KB
/
Copy pathstart_native.ps1
File metadata and controls
114 lines (98 loc) · 4.51 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
# SME v3.0.1 - Native Startup
# Updated: Focused on .venv313 and safe process management
$ErrorActionPreference = "Stop"
$SCRIPT_DIR = $PSScriptRoot
if (-not $SCRIPT_DIR) { $SCRIPT_DIR = Get-Location }
Set-Location $SCRIPT_DIR
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " SME v3.0.1 - Native Startup (No Sidecar)" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
# 1. Determine Python Executable - MUST use 3.13 (spacy incompatible with 3.14)
$PYTHON_EXE = "python"
if (Test-Path ".venv313\Scripts\python.exe") {
$PYTHON_EXE = "$SCRIPT_DIR\.venv313\Scripts\python.exe"
Write-Host "Using Virtual Environment: .venv313" -ForegroundColor Gray
} elseif ($PSVersionTable.PSEdition -eq "Desktop" -and (Get-Command py -ErrorAction SilentlyContinue)) {
$python313 = & py -3.13 -c "import sys; print(sys.executable)" 2>$null
if ($LASTEXITCODE -eq 0 -and $python313) {
$PYTHON_EXE = $python313.Trim()
Write-Host "Using Python 3.13: $PYTHON_EXE" -ForegroundColor Gray
} else {
Write-Host "Warning: Python 3.13 not found via py -3.13. Falling back to system python." -ForegroundColor Yellow
}
} else {
Write-Host "Warning: .venv313 not found. Falling back to system python." -ForegroundColor Yellow
}
$pythonVersion = & $PYTHON_EXE -c "import sys; print(sys.version_info[0]*10 + sys.version_info[1])" 2>$null
if ($LASTEXITCODE -ne 0 -or $pythonVersion -lt 13) {
Write-Host "Error: Python 3.13 required. Found: $($pythonVersion/10)" -ForegroundColor Red
Write-Host "Install Python 3.13 or create .venv313." -ForegroundColor Yellow
exit 1
}
if ($pythonVersion -gt 13) {
Write-Host "Error: Python 3.14 not supported (spacy incompatible)" -ForegroundColor Red
Write-Host "Install Python 3.13 or create .venv313." -ForegroundColor Yellow
exit 1
}
Write-Host "Python version check: OK ($([math]::Floor($pythonVersion/10)).$($pythonVersion%10))" -ForegroundColor Green
# Check for .env file
if (-not (Test-Path ".env")) {
Write-Host "Warning: .env file not found. Copy from .env.example" -ForegroundColor Yellow
}
# Function to check port
function Test-PortInUse {
param([int]$Port)
$connection = New-Object System.Net.Sockets.TcpClient
try {
$connection.Connect("localhost", $Port)
$connection.Close()
return $true
} catch {
return $false
}
}
if (Test-PortInUse -Port 8000) { Write-Host "Warning: Port 8000 in use" -ForegroundColor Yellow }
if (Test-PortInUse -Port 5173) { Write-Host "Warning: Port 5173 in use" -ForegroundColor Yellow }
# Create data directory
if (-not (Test-Path "data")) { New-Item -ItemType Directory -Path "data" | Out-Null }
$StartedProcesses = @()
Write-Host "[1/2] Starting SME Operator (port 8000)..." -ForegroundColor Green
$opProc = Start-Process $PYTHON_EXE -ArgumentList "-m src.api.main" -PassThru -NoNewWindow
$StartedProcesses += $opProc
Write-Host "[2/2] Starting Frontend (port 5173)..." -ForegroundColor Green
# npm run dev usually starts vite
$frontProc = Start-Process "npm" -ArgumentList "run dev" -Cwd "$SCRIPT_DIR\frontend" -PassThru -NoNewWindow
$StartedProcesses += $frontProc
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " All services started!" -ForegroundColor Green
Write-Host " Processes: $($StartedProcesses.Id -join ', ')" -ForegroundColor Gray
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host " Operator: http://localhost:8000" -ForegroundColor White
Write-Host " Frontend: http://localhost:5173" -ForegroundColor White
Write-Host ""
Write-Host " Press Ctrl+C to stop all services" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
try {
while ($true) {
# Check if processes are still running
foreach ($proc in $StartedProcesses) {
if ($proc.HasExited) {
Write-Host "Process $($proc.Id) has exited unexpectedly!" -ForegroundColor Red
break
}
}
Start-Sleep -Seconds 2
}
} finally {
Write-Host "`nStopping services..." -ForegroundColor Yellow
foreach ($proc in $StartedProcesses) {
if (-not $proc.HasExited) {
Write-Host "Terminating PID $($proc.Id)..." -ForegroundColor Gray
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
}
}
Write-Host "Cleanup complete." -ForegroundColor Green
}