Merge urllib3 fix into bootstraps; remove helper scripts
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -27,6 +27,7 @@ param(
|
||||
[switch]$NoInstall,
|
||||
[switch]$NoPlaywright,
|
||||
[string]$PlaywrightBrowsers = "chromium",
|
||||
[switch]$FixUrllib3,
|
||||
[switch]$Quiet
|
||||
)
|
||||
|
||||
@@ -191,9 +192,42 @@ if (-not $NoInstall) {
|
||||
Write-Log " $ $venvPython -m pip uninstall urllib3-future -y" "INFO"
|
||||
Write-Log " $ $venvPython -m pip install --upgrade --force-reinstall urllib3" "INFO"
|
||||
Write-Log " $ $venvPython -m pip install niquests -U" "INFO"
|
||||
|
||||
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 {
|
||||
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
|
||||
}
|
||||
} else {
|
||||
if ($Quiet) {
|
||||
Write-Log "Bootstrap detected a potentially broken 'urllib3' installation. Use -FixUrllib3 to attempt an automatic fix." "ERROR"
|
||||
exit 7
|
||||
}
|
||||
$ans = Read-Host "Attempt automatic fix now? (y/N)"
|
||||
if ($ans -eq 'y' -or $ans -eq 'Y') {
|
||||
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 {
|
||||
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
|
||||
}
|
||||
} else {
|
||||
Write-Log "Aborting bootstrap to avoid leaving a broken environment." "ERROR"
|
||||
exit 7
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Log "Failed to run environment verification: $_" "ERROR"
|
||||
}
|
||||
|
||||
@@ -24,10 +24,38 @@ PYTHON_CMD=""
|
||||
NOINSTALL=false
|
||||
FORCE=false
|
||||
QUIET=false
|
||||
FIX_URLLIB3=false
|
||||
# Playwright options
|
||||
PLAYWRIGHT_BROWSERS="chromium" # comma-separated (chromium,firefox,webkit) or 'all'
|
||||
NO_PLAYWRIGHT=false
|
||||
|
||||
attempt_fix_urllib3() {
|
||||
local venv_py="$1"
|
||||
echo "Attempting automatic urllib3 fix in venv: $venv_py" >&2
|
||||
# Temporarily disable set -e to inspect return codes ourselves
|
||||
set +e
|
||||
"$venv_py" -m pip uninstall urllib3-future -y >/dev/null 2>&1 || true
|
||||
"$venv_py" -m pip install --upgrade --force-reinstall urllib3
|
||||
local pip_ret=$?
|
||||
# Best-effort install/update for niquests; non-fatal
|
||||
"$venv_py" -m pip install niquests -U >/dev/null 2>&1 || true
|
||||
set -e
|
||||
|
||||
if [[ $pip_ret -ne 0 ]]; then
|
||||
echo "ERROR: pip failed to reinstall urllib3 (exit $pip_ret)" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
# Verify fix
|
||||
if "$venv_py" -c 'from SYS.env_check import check_urllib3_compat; ok,msg = check_urllib3_compat(); import sys; sys.exit(0 if ok else 2)'; then
|
||||
echo "Success: urllib3 issues resolved" >&2
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "ERROR: urllib3 fix attempt incomplete (import check failed)" >&2
|
||||
return 3
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
@@ -40,6 +68,7 @@ Options:
|
||||
--no-playwright Skip installing Playwright browsers (default: install chromium)
|
||||
--playwright-browsers <list> Comma-separated list of browsers to install (default: chromium)
|
||||
-q, --quiet Quiet / non-interactive mode; abort on errors instead of prompting
|
||||
-F, --fix-urllib3 Attempt to automatically fix known urllib3 issues in the venv if detected
|
||||
-f, --force Overwrite existing venv without prompting
|
||||
-h, --help Show this help
|
||||
EOF
|
||||
@@ -53,6 +82,7 @@ while [[ $# -gt 0 ]]; do
|
||||
-d|--desktop) DESKTOP=true; shift;;
|
||||
-n|--no-install) NOINSTALL=true; shift;;
|
||||
-f|--force) FORCE=true; shift;;
|
||||
-F|--fix-urllib3) FIX_URLLIB3=true; shift;;
|
||||
-q|--quiet) QUIET=true; shift;;
|
||||
-h|--help) usage; exit 0;;
|
||||
--no-playwright) NO_PLAYWRIGHT=true; shift;;
|
||||
@@ -172,8 +202,34 @@ if [[ "$NOINSTALL" != "true" ]]; then
|
||||
echo " $VENV_PY -m pip uninstall urllib3-future -y" >&2
|
||||
echo " $VENV_PY -m pip install --upgrade --force-reinstall urllib3" >&2
|
||||
echo " $VENV_PY -m pip install niquests -U" >&2
|
||||
echo "" >&2
|
||||
if [[ "$FIX_URLLIB3" == "true" ]]; then
|
||||
echo "Attempting automatic fix (--fix-urllib3 requested)..." >&2
|
||||
if attempt_fix_urllib3 "$VENV_PY"; then
|
||||
echo "Success: urllib3 issues resolved; continuing..." >&2
|
||||
else
|
||||
echo "ERROR: Automatic fix did not resolve the issue; inspect .pth files in site-packages (e.g., urllib3_future.pth) and remove them, then re-run with --fix-urllib3" >&2
|
||||
exit 7
|
||||
fi
|
||||
else
|
||||
if [[ "$QUIET" == "true" ]]; then
|
||||
echo "ERROR: Bootstrap detected a potentially broken 'urllib3' installation. Use --fix-urllib3 to attempt an automatic fix." >&2
|
||||
exit 7
|
||||
fi
|
||||
read -p "Attempt automatic fix now? (y/N) " REPLY
|
||||
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
|
||||
if attempt_fix_urllib3 "$VENV_PY"; then
|
||||
echo "Success: urllib3 issues resolved; continuing..." >&2
|
||||
else
|
||||
echo "ERROR: Automatic fix did not resolve the issue; aborting." >&2
|
||||
exit 7
|
||||
fi
|
||||
else
|
||||
echo "Aborting bootstrap. Re-run with --fix-urllib3 to attempt an automatic fix or run the commands above." >&2
|
||||
exit 7
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install Playwright browsers (default: chromium) unless explicitly disabled
|
||||
if [[ "$NO_PLAYWRIGHT" != "true" && "$NOINSTALL" != "true" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user