| param( |
| [ValidateSet('streamlit', 'panel')] |
| [string]$App = 'streamlit', |
|
|
| [int]$Port = 0, |
|
|
| [Alias('Host')] |
| [string]$Address = 'localhost', |
|
|
| [switch]$Reload, |
|
|
| [switch]$NoBrowser, |
|
|
| [string]$Entry |
| ) |
|
|
| $validApps = @('streamlit', 'panel') |
| if (-not $PSBoundParameters.ContainsKey('App')) { |
| Write-Host "Choisissez l'application à lancer :" -ForegroundColor Cyan |
| Write-Host "1) Streamlit" -ForegroundColor Yellow |
| Write-Host "2) Panel" -ForegroundColor Yellow |
| do { |
| $choice = Read-Host "Entrez 1 pour Streamlit, 2 pour Panel (Entrée = Streamlit)" |
| switch ($choice) { |
| '' { $App = 'streamlit'; $isValidChoice = $true } |
| '1' { $App = 'streamlit'; $isValidChoice = $true } |
| '2' { $App = 'panel'; $isValidChoice = $true } |
| default { |
| $choiceLower = $choice.ToLower() |
| if ($validApps -contains $choiceLower) { |
| $App = $choiceLower |
| $isValidChoice = $true |
| } |
| else { |
| Write-Host "Choix invalide. Réessayez." -ForegroundColor Red |
| $isValidChoice = $false |
| } |
| } |
| } |
| } until ($isValidChoice) |
| } |
|
|
| $ErrorActionPreference = 'Stop' |
|
|
| $repoRoot = $PSScriptRoot |
|
|
| if (-not $PSBoundParameters.ContainsKey('Port') -or $Port -eq 0) { |
| if ($App -eq 'panel') { |
| $Port = 5006 |
| } |
| else { |
| $Port = 8501 |
| } |
| } |
|
|
| $venvActivateCandidates = @( |
| (Join-Path $repoRoot '.venv\Scripts\Activate.ps1'), |
| (Join-Path $repoRoot 'venv\Scripts\Activate.ps1') |
| ) |
|
|
| $venvActivate = $venvActivateCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1 |
| if ($venvActivate) { |
| . $venvActivate |
| } |
|
|
| function Invoke-PythonModule { |
| param( |
| [Parameter(Mandatory = $true)] |
| [string]$Module, |
|
|
| [Parameter(Mandatory = $true)] |
| [string[]]$Args |
| ) |
|
|
| $python = Get-Command python -ErrorAction SilentlyContinue |
| if (-not $python) { |
| throw "python not found in PATH. Install Python or create/activate a venv (e.g. .\\.venv\\Scripts\\Activate.ps1)." |
| } |
|
|
| & $python.Source -m $Module @Args |
| } |
|
|
| if ($App -eq 'streamlit') { |
| if (-not $Entry) { $Entry = 'app.py' } |
| $entryPath = Join-Path $repoRoot $Entry |
| if (-not (Test-Path $entryPath)) { |
| throw "Streamlit entry not found: $entryPath" |
| } |
|
|
| $cmdArgs = @( |
| 'run', |
| $entryPath, |
| '--server.port', $Port, |
| '--server.address', $Address, |
| '--server.fileWatcherType', 'poll' |
| ) |
|
|
| if ($NoBrowser) { $cmdArgs += @('--server.headless', 'true') } |
| if ($Reload) { $cmdArgs += @('--server.runOnSave', 'true') } |
|
|
| Invoke-PythonModule -Module 'streamlit' -Args $cmdArgs |
| exit $LASTEXITCODE |
| } |
|
|
| if ($App -eq 'panel') { |
| if (-not $Entry) { $Entry = 'panel_app\panel_portal.py' } |
| $entryPath = Join-Path $repoRoot $Entry |
| if (-not (Test-Path $entryPath)) { |
| throw "Panel entry not found: $entryPath" |
| } |
|
|
| $cmdArgs = @( |
| 'serve', |
| $entryPath, |
| '--port', $Port, |
| '--address', $Address |
| ) |
|
|
| if (-not $NoBrowser) { $cmdArgs += '--show' } |
| if ($Reload) { $cmdArgs += '--autoreload' } |
|
|
| Invoke-PythonModule -Module 'panel' -Args $cmdArgs |
| exit $LASTEXITCODE |
| } |
|
|
| throw "Unknown app: $App" |
|
|