setup.ps1 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. param(
  2. [switch]$GenLock
  3. )
  4. $ErrorActionPreference = 'Stop'
  5. # Project root
  6. $root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
  7. Set-Location $root
  8. # Find Python
  9. $usePyLauncher = $false
  10. if (Get-Command py -ErrorAction SilentlyContinue) {
  11. $usePyLauncher = $true
  12. } elseif (-not (Get-Command python -ErrorAction SilentlyContinue)) {
  13. Write-Host "[ERROR] Python not found. Please install Python 3.12.10 and rerun." -ForegroundColor Red
  14. exit 1
  15. }
  16. # Create venv if missing
  17. if (-not (Test-Path '.venv')) {
  18. if ($usePyLauncher) {
  19. & py -3.12 -m venv .venv
  20. } else {
  21. & python -m venv .venv
  22. }
  23. }
  24. # Paths to venv python/pip
  25. $venvPython = Join-Path $root '.venv\Scripts\python.exe'
  26. $venvPip = Join-Path $root '.venv\Scripts\pip.exe'
  27. # Upgrade tooling
  28. & $venvPython -m pip install --upgrade pip wheel setuptools
  29. # Determine scan root
  30. $scanRoot = '.'
  31. if (Test-Path 'src') { $scanRoot = 'src' }
  32. # Run import scanner if available
  33. $scanScript = Join-Path $root 'tools\scan_imports.py'
  34. if (Test-Path $scanScript) {
  35. Write-Host "[INFO] Scanning imports in $scanRoot ..."
  36. & $venvPython $scanScript --src $scanRoot --out 'requirements.in' --update
  37. } else {
  38. Write-Host "[INFO] tools\scan_imports.py not found. Skipping import scan."
  39. }
  40. # Install dependencies
  41. if (Test-Path 'pyproject.toml') {
  42. Write-Host "[INFO] Installing from pyproject.toml"
  43. & $venvPip install -e .
  44. }
  45. if (Test-Path 'requirements.in') {
  46. Write-Host "[INFO] Installing from requirements.in"
  47. & $venvPip install -r 'requirements.in'
  48. }
  49. # Generate lock file
  50. if ($GenLock -or -not (Test-Path 'requirements.lock.txt')) {
  51. Write-Host "[INFO] Writing requirements.lock.txt"
  52. & $venvPip freeze | Out-File -Encoding ascii 'requirements.lock.txt'
  53. }
  54. Write-Host "[OK] Setup finished." -ForegroundColor Green