mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-07 07:18:18 +00:00
feat(zstart): warn when falling back to system python (no project venv)
A python project with no .venv (or only a Windows .venv when on WSL) silently ran under the system interpreter, which usually lacks the project's deps - producing a cryptic ModuleNotFoundError far from the cause. Now zstart prints a clear warning naming the missing venv and the one-liner to create it, before starting. Bash + PowerShell.
This commit is contained in:
parent
fd53acc23d
commit
c4bf4a15af
12
bash/zstart
12
bash/zstart
@ -68,7 +68,7 @@ start_prep() { # <key>
|
||||
}
|
||||
|
||||
start_python() { # <key> <port>
|
||||
local key="$1" port="$2" root module app exe bv="" run_cmd=() what
|
||||
local key="$1" port="$2" root module app exe bv="" run_cmd=() what using_venv=1
|
||||
root="$(zproj_root "$key")"
|
||||
module="$(zproj "$key" .startModule)"
|
||||
app="$(zproj "$key" .startApp)"
|
||||
@ -81,8 +81,8 @@ start_python() { # <key> <port>
|
||||
# executable but can't exec, so guard that branch to fall through to python3.
|
||||
if [ -x "$root/.venv/bin/python" ]; then exe="$root/.venv/bin/python"
|
||||
elif [ -x "$root/.venv/Scripts/python.exe" ] && [[ "$OSTYPE" == msys* || "$OSTYPE" == cygwin* ]]; then exe="$root/.venv/Scripts/python.exe"
|
||||
elif command -v python3 >/dev/null 2>&1; then exe="python3"
|
||||
else exe="python"; fi
|
||||
elif command -v python3 >/dev/null 2>&1; then exe="python3"; using_venv=0
|
||||
else exe="python"; using_venv=0; fi
|
||||
|
||||
# Optional convention: scripts/build_version_tool.py bumps the version on dev start.
|
||||
if [ -f "$root/scripts/build_version_tool.py" ]; then
|
||||
@ -102,6 +102,12 @@ start_python() { # <key> <port>
|
||||
fi
|
||||
|
||||
printf '\n'; info "=== zstart ($(zproj "$key" .label)) ==="
|
||||
# No project venv found - warn, since the system interpreter usually lacks the
|
||||
# app's deps (the failure would otherwise be a cryptic ModuleNotFoundError).
|
||||
if [ "$using_venv" -eq 0 ]; then
|
||||
warn "No project venv at $root/.venv - using system '$exe' (its deps may be missing)."
|
||||
dim " Create one: (cd \"$root\" && python3 -m venv .venv && .venv/bin/pip install -e .)"
|
||||
fi
|
||||
info "Starting $what on port $port..."
|
||||
[ -n "$bv" ] && note "Build Version: $bv"
|
||||
show_project_motd "$root"
|
||||
|
||||
@ -56,7 +56,8 @@ function Start-PythonProject {
|
||||
}
|
||||
Set-Location -LiteralPath $root
|
||||
$venvPython = Join-Path $root ".venv\Scripts\python.exe"
|
||||
$exe = if (Test-Path -LiteralPath $venvPython) { $venvPython } else { "python" }
|
||||
$usingVenv = Test-Path -LiteralPath $venvPython
|
||||
$exe = if ($usingVenv) { $venvPython } else { "python" }
|
||||
|
||||
# Optional convention: if the project ships scripts/build_version_tool.py,
|
||||
# bump (or at least read) the build version on every dev start.
|
||||
@ -92,6 +93,10 @@ function Start-PythonProject {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== zstart ($($Proj.label)) ===" -ForegroundColor Cyan
|
||||
if (-not $usingVenv) {
|
||||
Write-Host "No project venv at $root\.venv - using system 'python' (its deps may be missing)." -ForegroundColor Yellow
|
||||
Write-Host " Create one: python -m venv .venv; .\.venv\Scripts\pip install -e ." -ForegroundColor DarkGray
|
||||
}
|
||||
Write-Host "Starting $what on port $ListenPort..." -ForegroundColor Cyan
|
||||
if (-not [string]::IsNullOrWhiteSpace($buildVersion)) {
|
||||
Write-Host "Build Version: $buildVersion" -ForegroundColor Magenta
|
||||
|
||||
Loading…
Reference in New Issue
Block a user