Add PowerShell launcher script with automatic venv activation, configurable app selection, port/address parameters, and reload/browser control for Streamlit and Panel deployments
Browse files- run_app.ps1 +99 -0
run_app.ps1
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[ValidateSet('streamlit', 'panel')]
|
| 3 |
+
[string]$App = 'streamlit',
|
| 4 |
+
|
| 5 |
+
[int]$Port = 0,
|
| 6 |
+
|
| 7 |
+
[Alias('Host')]
|
| 8 |
+
[string]$Address = 'localhost',
|
| 9 |
+
|
| 10 |
+
[switch]$Reload,
|
| 11 |
+
|
| 12 |
+
[switch]$NoBrowser,
|
| 13 |
+
|
| 14 |
+
[string]$Entry
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
$ErrorActionPreference = 'Stop'
|
| 18 |
+
|
| 19 |
+
$repoRoot = $PSScriptRoot
|
| 20 |
+
|
| 21 |
+
if (-not $PSBoundParameters.ContainsKey('Port') -or $Port -eq 0) {
|
| 22 |
+
if ($App -eq 'panel') {
|
| 23 |
+
$Port = 5006
|
| 24 |
+
}
|
| 25 |
+
else {
|
| 26 |
+
$Port = 8501
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
$venvActivateCandidates = @(
|
| 31 |
+
(Join-Path $repoRoot '.venv\Scripts\Activate.ps1'),
|
| 32 |
+
(Join-Path $repoRoot 'venv\Scripts\Activate.ps1')
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
$venvActivate = $venvActivateCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
|
| 36 |
+
if ($venvActivate) {
|
| 37 |
+
. $venvActivate
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function Invoke-PythonModule {
|
| 41 |
+
param(
|
| 42 |
+
[Parameter(Mandatory = $true)]
|
| 43 |
+
[string]$Module,
|
| 44 |
+
|
| 45 |
+
[Parameter(Mandatory = $true)]
|
| 46 |
+
[string[]]$Args
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
$python = Get-Command python -ErrorAction SilentlyContinue
|
| 50 |
+
if (-not $python) {
|
| 51 |
+
throw "python not found in PATH. Install Python or create/activate a venv (e.g. .\\.venv\\Scripts\\Activate.ps1)."
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
& $python.Source -m $Module @Args
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if ($App -eq 'streamlit') {
|
| 58 |
+
if (-not $Entry) { $Entry = 'app.py' }
|
| 59 |
+
$entryPath = Join-Path $repoRoot $Entry
|
| 60 |
+
if (-not (Test-Path $entryPath)) {
|
| 61 |
+
throw "Streamlit entry not found: $entryPath"
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
$cmdArgs = @(
|
| 65 |
+
'run',
|
| 66 |
+
$entryPath,
|
| 67 |
+
'--server.port', $Port,
|
| 68 |
+
'--server.address', $Address
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if ($NoBrowser) { $cmdArgs += @('--server.headless', 'true') }
|
| 72 |
+
if ($Reload) { $cmdArgs += @('--server.runOnSave', 'true') }
|
| 73 |
+
|
| 74 |
+
Invoke-PythonModule -Module 'streamlit' -Args $cmdArgs
|
| 75 |
+
exit $LASTEXITCODE
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if ($App -eq 'panel') {
|
| 79 |
+
if (-not $Entry) { $Entry = 'panel_app\panel_portal.py' }
|
| 80 |
+
$entryPath = Join-Path $repoRoot $Entry
|
| 81 |
+
if (-not (Test-Path $entryPath)) {
|
| 82 |
+
throw "Panel entry not found: $entryPath"
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
$cmdArgs = @(
|
| 86 |
+
'serve',
|
| 87 |
+
$entryPath,
|
| 88 |
+
'--port', $Port,
|
| 89 |
+
'--address', $Address
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
if (-not $NoBrowser) { $cmdArgs += '--show' }
|
| 93 |
+
if ($Reload) { $cmdArgs += '--autoreload' }
|
| 94 |
+
|
| 95 |
+
Invoke-PythonModule -Module 'panel' -Args $cmdArgs
|
| 96 |
+
exit $LASTEXITCODE
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
throw "Unknown app: $App"
|