param( [switch]$GenLock ) $ErrorActionPreference = 'Stop' # Project root $root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path Set-Location $root # Find Python $usePyLauncher = $false if (Get-Command py -ErrorAction SilentlyContinue) { $usePyLauncher = $true } elseif (-not (Get-Command python -ErrorAction SilentlyContinue)) { Write-Host "[ERROR] Python not found. Please install Python 3.12.10 and rerun." -ForegroundColor Red exit 1 } # Create venv if missing if (-not (Test-Path '.venv')) { if ($usePyLauncher) { & py -3.12 -m venv .venv } else { & python -m venv .venv } } # Paths to venv python/pip $venvPython = Join-Path $root '.venv\Scripts\python.exe' $venvPip = Join-Path $root '.venv\Scripts\pip.exe' # Upgrade tooling & $venvPython -m pip install --upgrade pip wheel setuptools # Determine scan root $scanRoot = '.' if (Test-Path 'src') { $scanRoot = 'src' } # Run import scanner if available $scanScript = Join-Path $root 'tools\scan_imports.py' if (Test-Path $scanScript) { Write-Host "[INFO] Scanning imports in $scanRoot ..." & $venvPython $scanScript --src $scanRoot --out 'requirements.in' --update } else { Write-Host "[INFO] tools\scan_imports.py not found. Skipping import scan." } # Install dependencies if (Test-Path 'pyproject.toml') { Write-Host "[INFO] Installing from pyproject.toml" & $venvPip install -e . } if (Test-Path 'requirements.in') { Write-Host "[INFO] Installing from requirements.in" & $venvPip install -r 'requirements.in' } # Generate lock file if ($GenLock -or -not (Test-Path 'requirements.lock.txt')) { Write-Host "[INFO] Writing requirements.lock.txt" & $venvPip freeze | Out-File -Encoding ascii 'requirements.lock.txt' } Write-Host "[OK] Setup finished." -ForegroundColor Green