dfd
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
nose
2025-12-24 02:42:13 -08:00
parent 032cf9f191
commit 32494a97ac
2 changed files with 201 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ param(
[switch]$NoPlaywright,
[string]$PlaywrightBrowsers = "chromium",
[switch]$FixUrllib3,
[switch]$RemovePth,
[switch]$Quiet
)
@@ -193,17 +194,98 @@ if (-not $NoInstall) {
Write-Log " $ $venvPython -m pip install --upgrade --force-reinstall urllib3" "INFO"
Write-Log " $ $venvPython -m pip install niquests -U" "INFO"
function Get-SitePackages {
param($python)
try {
$json = & $python -c "import site, sysconfig, json; p=[];
try:
p.extend(site.getsitepackages())
except Exception:
pass
try:
pp = sysconfig.get_paths().get('purelib')
if pp:
p.append(pp)
except Exception:
pass
seen = []
out = []
for s in p:
if s and s not in seen:
seen.append(s)
out.append(s)
print(json.dumps(out))"
return $json | ConvertFrom-Json
} catch {
return @()
}
}
function Find-InterferingPth {
param($python)
$pths = @()
$sps = Get-SitePackages -python $python
foreach ($sp in $sps) {
if (Test-Path $sp) {
Get-ChildItem -Path $sp -Filter *.pth -File -ErrorAction SilentlyContinue | ForEach-Object {
$c = Get-Content -Path $_.FullName -ErrorAction SilentlyContinue | Out-String
if ($c -match 'urllib3_future' -or $c -match 'urllib3-future') {
$pths += $_.FullName
}
}
}
}
return $pths
}
# Helper to try removal and re-verify
function RemovePthAndVerify {
param($python, $paths)
foreach ($p in $paths) { Remove-Item -Force $p -ErrorAction SilentlyContinue }
try { & $python -m pip install --upgrade --force-reinstall urllib3 } catch { Write-Log "pip install failed: $_" "ERROR"; return $false }
& $python -c "import sys; from SYS.env_check import check_urllib3_compat; ok, msg = check_urllib3_compat(); print(msg); sys.exit(0 if ok else 2)"
return ($LASTEXITCODE -eq 0)
}
if ($FixUrllib3) {
Write-Log "Attempting automatic fix (--FixUrllib3)..." "INFO"
try { & $venvPython -m pip uninstall urllib3-future -y } catch {}
try { & $venvPython -m pip install --upgrade --force-reinstall urllib3 } catch { Write-Log "pip install failed: $_" "ERROR"; exit 7 }
try { & $venvPython -m pip install niquests -U } catch { Write-Log "pip install niquests failed: $_" "ERROR" }
& $venvPython -c "import sys; from SYS.env_check import check_urllib3_compat; ok, msg = check_urllib3_compat(); print(msg); sys.exit(0 if ok else 2)"
if ($LASTEXITCODE -ne 0) {
Write-Log "Automatic fix failed; aborting." "ERROR"
exit 7
} else {
if ($LASTEXITCODE -eq 0) {
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
} else {
Write-Log "Initial automatic fix did not resolve the issue; searching for interfering .pth files..." "INFO"
$pths = Find-InterferingPth -python $venvPython
if ($pths.Count -eq 0) {
Write-Log "No interfering .pth files found; aborting." "ERROR"
exit 7
}
Write-Log ("Found interfering .pth files:`n" + ($pths -join "`n")) "ERROR"
if ($RemovePth) {
Write-Log "Removing .pth files as requested..." "INFO"
if (RemovePthAndVerify -python $venvPython -paths $pths) {
Write-Log "Success: urllib3 problems resolved after .pth removal; continuing." "INFO"
} else {
Write-Log "Automatic fix failed even after .pth removal; aborting." "ERROR"
exit 7
}
} else {
if ($Quiet) { Write-Log "Detected interfering .pth files but cannot prompt in quiet mode. Use -RemovePth to remove them automatically." "ERROR"; exit 7 }
$ans = Read-Host "Remove these files now? (y/N)"
if ($ans -eq 'y' -or $ans -eq 'Y') {
if (RemovePthAndVerify -python $venvPython -paths $pths) {
Write-Log "Success: urllib3 problems resolved after .pth removal; continuing." "INFO"
} else {
Write-Log "Automatic fix failed even after .pth removal; aborting." "ERROR"
exit 7
}
} else {
Write-Log "User declined to remove .pth files. Aborting." "ERROR"
exit 7
}
}
}
} else {
if ($Quiet) {
@@ -216,11 +298,38 @@ if (-not $NoInstall) {
try { & $venvPython -m pip install --upgrade --force-reinstall urllib3 } catch { Write-Log "pip install failed: $_" "ERROR"; exit 7 }
try { & $venvPython -m pip install niquests -U } catch { Write-Log "pip install niquests failed: $_" "ERROR" }
& $venvPython -c "import sys; from SYS.env_check import check_urllib3_compat; ok, msg = check_urllib3_compat(); print(msg); sys.exit(0 if ok else 2)"
if ($LASTEXITCODE -ne 0) {
Write-Log "Automatic fix failed; aborting." "ERROR"
exit 7
} else {
if ($LASTEXITCODE -eq 0) {
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
} else {
Write-Log "Initial automatic fix did not resolve the issue; searching for interfering .pth files..." "INFO"
$pths = Find-InterferingPth -python $venvPython
if ($pths.Count -eq 0) {
Write-Log "No interfering .pth files found; aborting." "ERROR"
exit 7
}
Write-Log ("Found interfering .pth files:`n" + ($pths -join "`n")) "ERROR"
if ($RemovePth) {
Write-Log "Removing .pth files as requested..." "INFO"
if (RemovePthAndVerify -python $venvPython -paths $pths) {
Write-Log "Success: urllib3 problems resolved after .pth removal; continuing." "INFO"
} else {
Write-Log "Automatic fix failed even after .pth removal; aborting." "ERROR"
exit 7
}
} else {
$ans2 = Read-Host "Remove these files now? (y/N)"
if ($ans2 -eq 'y' -or $ans2 -eq 'Y') {
if (RemovePthAndVerify -python $venvPython -paths $pths) {
Write-Log "Success: urllib3 problems resolved after .pth removal; continuing." "INFO"
} else {
Write-Log "Automatic fix failed even after .pth removal; aborting." "ERROR"
exit 7
}
} else {
Write-Log "User declined to remove .pth files. Aborting." "ERROR"
exit 7
}
}
}
} else {
Write-Log "Aborting bootstrap to avoid leaving a broken environment." "ERROR"