build_runner.ps1 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Build runner.py into standalone api_runner.exe (Nuitka)
  2. # Usage in PowerShell:
  3. # .\build_runner.ps1
  4. $ErrorActionPreference = "Stop"
  5. Set-Location $PSScriptRoot
  6. Write-Host "[1/4] Check Python 3.11 ..." -ForegroundColor Cyan
  7. $python = $null
  8. if (Get-Command py -ErrorAction SilentlyContinue) {
  9. $python = "py -3.11"
  10. } elseif (Get-Command python -ErrorAction SilentlyContinue) {
  11. $python = "python"
  12. } else {
  13. Write-Host "ERROR: Python not found. Please install Python 3.11." -ForegroundColor Red
  14. exit 1
  15. }
  16. Invoke-Expression "$python --version"
  17. Write-Host "[2/4] Install build dependencies ..." -ForegroundColor Cyan
  18. Invoke-Expression "$python -m pip install -r requirements.txt"
  19. Write-Host "[3/4] Check required files ..." -ForegroundColor Cyan
  20. foreach ($file in @("runner.py", "license.lic", "public_key.pem")) {
  21. if (-not (Test-Path $file)) {
  22. Write-Host "ERROR: $file not found." -ForegroundColor Red
  23. exit 1
  24. }
  25. }
  26. if (-not (Test-Path "entry.cp311-win_amd64.pyd")) {
  27. Write-Host "ERROR: entry.cp311-win_amd64.pyd not found." -ForegroundColor Red
  28. exit 1
  29. }
  30. foreach ($src in @("entry.py", "data_clean.py", "frequency_filter.py")) {
  31. if (Test-Path $src) {
  32. Write-Host "ERROR: Found $src - remove algorithm source files before building." -ForegroundColor Red
  33. exit 1
  34. }
  35. }
  36. Write-Host "[4/4] Build api_runner.exe ..." -ForegroundColor Cyan
  37. Remove-Item -Recurse -Force runner.dist, runner.build -ErrorAction SilentlyContinue
  38. $env:NUITKA_CACHE_DIR = Join-Path $env:TEMP "nuitka-cache"
  39. Invoke-Expression @"
  40. $python -m nuitka runner.py `
  41. --standalone `
  42. --jobs=1 `
  43. --lto=no `
  44. --assume-yes-for-downloads `
  45. --output-filename=api_runner.exe `
  46. --include-package=cryptography `
  47. --include-package=numpy `
  48. --include-package=pandas `
  49. --include-package=scipy `
  50. --include-package=matplotlib `
  51. --enable-plugin=matplotlib `
  52. --include-module=numpy.testing `
  53. --nofollow-import-to=tkinter `
  54. --nofollow-import-to=matplotlib.tests `
  55. --nofollow-import-to=pandas.tests `
  56. --nofollow-import-to=scipy.tests `
  57. --include-data-files=entry.cp311-win_amd64.pyd=entry.cp311-win_amd64.pyd `
  58. --include-data-files=license.lic=license.lic `
  59. --include-data-files=public_key.pem=public_key.pem
  60. "@
  61. if ($LASTEXITCODE -ne 0) {
  62. Write-Host "ERROR: Build failed." -ForegroundColor Red
  63. exit 1
  64. }
  65. Write-Host ""
  66. Write-Host "SUCCESS: $PSScriptRoot\runner.dist\api_runner.exe" -ForegroundColor Green
  67. Write-Host "Next: cd to project root and run: npm run electron:dev" -ForegroundColor Green