mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
fix(install.ps1): restore EAP=Continue around uv python install, skip Store stub (#26586)
Fresh Windows installs were failing on first run with:
⚠ uv python install error: Downloading cpython-3.11.15-windows-x86_64-none (24.5MiB)
✗ Installation failed: Python was not found; run without arguments
to install from the Microsoft Store...
Two bugs compounding:
1) EAP=Stop swallows uv's stderr progress as an exception. uv writes
download progress ("Downloading cpython-3.11.15-windows-x86_64-none
(24.5MiB)") to stderr. With $ErrorActionPreference = "Stop" set at
the top of the script plus 2>&1 capture, PowerShell wraps each stderr
line as an ErrorRecord and throws on the first one — even though uv
exits 0 and Python was installed successfully. This was previously
fixed in commit ec1714e71 (May 8) but lost in the May 12 release
squash (413990c94). Reapply the EAP=Continue + verify-via
'uv python find' pattern.
2) System-python fallback invokes the Microsoft Store stub. When the uv
paths fall through, the legacy 'python --version' check invokes
%LOCALAPPDATA%\\Microsoft\\WindowsApps\\python.exe, a 0-byte
reparse-point stub that prints 'Python was not found...' to stdout
and exits non-zero. Get-Command matches it. The resulting error
message is what the user sees as the final installer crash. Detect
and skip the stub by checking for the \\WindowsApps\\ path
component or a 0-byte file size before invoking python.
Also save/restore EAP defensively in the catch blocks so a throw before
the assignment can't leave EAP in 'Continue'.
This commit is contained in:
parent
bd3a5873e1
commit
622c27e55c
1 changed files with 62 additions and 15 deletions
|
|
@ -145,19 +145,39 @@ function Test-Python {
|
||||||
# Python not found — use uv to install it (no admin needed!)
|
# Python not found — use uv to install it (no admin needed!)
|
||||||
Write-Info "Python $PythonVersion not found, installing via uv..."
|
Write-Info "Python $PythonVersion not found, installing via uv..."
|
||||||
try {
|
try {
|
||||||
|
# Temporarily relax ErrorActionPreference: uv writes download progress
|
||||||
|
# ("Downloading cpython-3.11.15-windows-x86_64-none (24.5MiB)") to
|
||||||
|
# stderr. With $ErrorActionPreference = "Stop" (set at the top of this
|
||||||
|
# script) PowerShell wraps stderr lines from native commands as
|
||||||
|
# ErrorRecord objects when captured via 2>&1, then throws a terminating
|
||||||
|
# exception on the first one — even though uv exits 0 and Python was
|
||||||
|
# installed successfully. Verify success via `uv python find`
|
||||||
|
# afterwards, which is the reliable signal regardless of exit-code
|
||||||
|
# semantics or stderr noise. This fix was previously landed as
|
||||||
|
# commit ec1714e71 and then lost in a release squash; reapplied here.
|
||||||
|
$prevEAP = $ErrorActionPreference
|
||||||
|
$ErrorActionPreference = "Continue"
|
||||||
$uvOutput = & $UvCmd python install $PythonVersion 2>&1
|
$uvOutput = & $UvCmd python install $PythonVersion 2>&1
|
||||||
if ($LASTEXITCODE -eq 0) {
|
$uvExitCode = $LASTEXITCODE
|
||||||
$pythonPath = & $UvCmd python find $PythonVersion 2>$null
|
$ErrorActionPreference = $prevEAP
|
||||||
if ($pythonPath) {
|
|
||||||
$ver = & $pythonPath --version 2>$null
|
# Check if Python is now available (more reliable than exit code
|
||||||
Write-Success "Python installed: $ver"
|
# since uv may return non-zero due to "already installed" etc.)
|
||||||
return $true
|
$pythonPath = & $UvCmd python find $PythonVersion 2>$null
|
||||||
}
|
if ($pythonPath) {
|
||||||
} else {
|
$ver = & $pythonPath --version 2>$null
|
||||||
|
Write-Success "Python installed: $ver"
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
|
||||||
|
# uv ran but Python still not findable — show what happened
|
||||||
|
if ($uvExitCode -ne 0) {
|
||||||
Write-Warn "uv python install output:"
|
Write-Warn "uv python install output:"
|
||||||
Write-Host $uvOutput -ForegroundColor DarkGray
|
Write-Host $uvOutput -ForegroundColor DarkGray
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
# Restore EAP in case the try block threw before the assignment
|
||||||
|
if ($prevEAP) { $ErrorActionPreference = $prevEAP }
|
||||||
Write-Warn "uv python install error: $_"
|
Write-Warn "uv python install error: $_"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,15 +195,42 @@ function Test-Python {
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fallback: try system python
|
# Fallback: try system python — but skip the Microsoft Store stub.
|
||||||
if (Get-Command python -ErrorAction SilentlyContinue) {
|
# On Windows, %LOCALAPPDATA%\Microsoft\WindowsApps\python.exe is a 0-byte
|
||||||
$sysVer = python --version 2>$null
|
# reparse-point stub that prints "Python was not found; run without
|
||||||
if ($sysVer -match "3\.(1[0-9]|[1-9][0-9])") {
|
# arguments to install from the Microsoft Store..." to stdout and exits
|
||||||
Write-Success "Using system Python: $sysVer"
|
# non-zero. Get-Command finds it; invoking it produces a confusing error
|
||||||
return $true
|
# that the user sees as our installer crashing.
|
||||||
|
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||||
|
if ($pythonCmd) {
|
||||||
|
$isStoreStub = $false
|
||||||
|
try {
|
||||||
|
$pythonSource = $pythonCmd.Source
|
||||||
|
if ($pythonSource -and $pythonSource -like "*\WindowsApps\*") {
|
||||||
|
$isStoreStub = $true
|
||||||
|
} else {
|
||||||
|
# Even outside WindowsApps, a 0-byte file is the stub
|
||||||
|
$item = Get-Item $pythonSource -ErrorAction SilentlyContinue
|
||||||
|
if ($item -and $item.Length -eq 0) { $isStoreStub = $true }
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
if (-not $isStoreStub) {
|
||||||
|
try {
|
||||||
|
$prevEAP2 = $ErrorActionPreference
|
||||||
|
$ErrorActionPreference = "Continue"
|
||||||
|
$sysVer = & python --version 2>&1
|
||||||
|
$ErrorActionPreference = $prevEAP2
|
||||||
|
if ($sysVer -match "Python 3\.(1[0-9]|[1-9][0-9])") {
|
||||||
|
Write-Success "Using system Python: $sysVer"
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
if ($prevEAP2) { $ErrorActionPreference = $prevEAP2 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Err "Failed to install Python $PythonVersion"
|
Write-Err "Failed to install Python $PythonVersion"
|
||||||
Write-Info "Install Python 3.11 manually, then re-run this script:"
|
Write-Info "Install Python 3.11 manually, then re-run this script:"
|
||||||
Write-Info " https://www.python.org/downloads/"
|
Write-Info " https://www.python.org/downloads/"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue