param( [switch]$Force ) $ErrorActionPreference = "Stop" $Root = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..") $OfflineDeps = Join-Path $Root "offline-deps" $ServiceDir = Join-Path $Root "service" $Installer = Join-Path $OfflineDeps "installers\python-3.13.12-amd64.exe" $PythonRuntime = Join-Path $OfflineDeps "python-runtime" $RuntimePython = Join-Path $PythonRuntime "python.exe" $Venv = Join-Path $Root "venv" $VenvPython = Join-Path $Venv "Scripts\python.exe" $Wheels = Join-Path $OfflineDeps "wheels" $ServiceEnv = Join-Path $ServiceDir ".env.local" if (!(Test-Path -LiteralPath $ServiceDir)) { throw "Could not find service directory. Run this script from the AS_Test project layout." } if (!(Test-Path -LiteralPath $Installer)) { throw "Missing Python installer: $Installer" } if (!(Test-Path -LiteralPath $Wheels)) { throw "Missing wheels directory: $Wheels" } if ($Force -and (Test-Path -LiteralPath $Venv)) { Remove-Item -LiteralPath $Venv -Recurse -Force } if (!(Test-Path -LiteralPath $RuntimePython)) { New-Item -ItemType Directory -Force -Path $PythonRuntime | Out-Null $args = @( "/quiet", "InstallAllUsers=0", "TargetDir=$PythonRuntime", "Include_launcher=0", "PrependPath=0", "Include_test=0", "Include_doc=0", "Include_tcltk=0", "Include_pip=1" ) $process = Start-Process -FilePath $Installer -ArgumentList $args -Wait -PassThru -WindowStyle Hidden if ($process.ExitCode -ne 0) { throw "Python installer failed with exit code $($process.ExitCode)" } } & $RuntimePython --version if (!(Test-Path -LiteralPath $VenvPython)) { & $RuntimePython -m venv $Venv } & $VenvPython -m pip install --no-index --find-links $Wheels jsbsim==1.3.0 & $VenvPython -c "import jsbsim, numpy; print('jsbsim', jsbsim.__version__); print('numpy', numpy.__version__)" @" SIM_BACKEND=jsbsim JSBSIM_PYTHON=$VenvPython "@ | Set-Content -LiteralPath $ServiceEnv -Encoding UTF8 Write-Host "" Write-Host "JSBSim offline environment is ready." Write-Host "Service env written to: $ServiceEnv" Write-Host "" Write-Host "Start service with:" Write-Host " cd $Root\service" Write-Host " npm.cmd run start"