# Build runner.py into standalone api_runner.exe (Nuitka) # Usage in PowerShell: # .\build_runner.ps1 $ErrorActionPreference = "Stop" Set-Location $PSScriptRoot Write-Host "[1/4] Check Python 3.11 ..." -ForegroundColor Cyan $python = $null if (Get-Command py -ErrorAction SilentlyContinue) { $python = "py -3.11" } elseif (Get-Command python -ErrorAction SilentlyContinue) { $python = "python" } else { Write-Host "ERROR: Python not found. Please install Python 3.11." -ForegroundColor Red exit 1 } Invoke-Expression "$python --version" Write-Host "[2/4] Install build dependencies ..." -ForegroundColor Cyan Invoke-Expression "$python -m pip install -r requirements.txt" Write-Host "[3/4] Check required files ..." -ForegroundColor Cyan foreach ($file in @("runner.py", "license.lic", "public_key.pem")) { if (-not (Test-Path $file)) { Write-Host "ERROR: $file not found." -ForegroundColor Red exit 1 } } if (-not (Test-Path "entry.cp311-win_amd64.pyd")) { Write-Host "ERROR: entry.cp311-win_amd64.pyd not found." -ForegroundColor Red exit 1 } foreach ($src in @("entry.py", "data_clean.py", "frequency_filter.py")) { if (Test-Path $src) { Write-Host "ERROR: Found $src - remove algorithm source files before building." -ForegroundColor Red exit 1 } } Write-Host "[4/4] Build api_runner.exe ..." -ForegroundColor Cyan Remove-Item -Recurse -Force runner.dist, runner.build -ErrorAction SilentlyContinue $env:NUITKA_CACHE_DIR = Join-Path $env:TEMP "nuitka-cache" Invoke-Expression @" $python -m nuitka runner.py ` --standalone ` --jobs=1 ` --lto=no ` --assume-yes-for-downloads ` --output-filename=api_runner.exe ` --include-package=cryptography ` --include-package=numpy ` --include-package=pandas ` --include-package=scipy ` --include-package=matplotlib ` --enable-plugin=matplotlib ` --include-module=numpy.testing ` --nofollow-import-to=tkinter ` --nofollow-import-to=matplotlib.tests ` --nofollow-import-to=pandas.tests ` --nofollow-import-to=scipy.tests ` --include-data-files=entry.cp311-win_amd64.pyd=entry.cp311-win_amd64.pyd ` --include-data-files=license.lic=license.lic ` --include-data-files=public_key.pem=public_key.pem "@ if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: Build failed." -ForegroundColor Red exit 1 } Write-Host "" Write-Host "SUCCESS: $PSScriptRoot\runner.dist\api_runner.exe" -ForegroundColor Green Write-Host "Next: cd to project root and run: npm run electron:dev" -ForegroundColor Green