db_query / run_app.ps1
DavMelchi's picture
Add file watcher polling mode to Streamlit launch configuration for improved cross-platform file change detection
de54a83
param(
[ValidateSet('streamlit', 'panel')]
[string]$App = 'streamlit',
[int]$Port = 0,
[Alias('Host')]
[string]$Address = 'localhost',
[switch]$Reload,
[switch]$NoBrowser,
[string]$Entry
)
$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"