dfd
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:
@@ -28,6 +28,7 @@ param(
|
|||||||
[switch]$NoPlaywright,
|
[switch]$NoPlaywright,
|
||||||
[string]$PlaywrightBrowsers = "chromium",
|
[string]$PlaywrightBrowsers = "chromium",
|
||||||
[switch]$FixUrllib3,
|
[switch]$FixUrllib3,
|
||||||
|
[switch]$RemovePth,
|
||||||
[switch]$Quiet
|
[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 --upgrade --force-reinstall urllib3" "INFO"
|
||||||
Write-Log " $ $venvPython -m pip install niquests -U" "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) {
|
if ($FixUrllib3) {
|
||||||
Write-Log "Attempting automatic fix (--FixUrllib3)..." "INFO"
|
Write-Log "Attempting automatic fix (--FixUrllib3)..." "INFO"
|
||||||
try { & $venvPython -m pip uninstall urllib3-future -y } catch {}
|
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 --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" }
|
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)"
|
& $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) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Log "Automatic fix failed; aborting." "ERROR"
|
|
||||||
exit 7
|
|
||||||
} else {
|
|
||||||
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
|
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 {
|
} else {
|
||||||
if ($Quiet) {
|
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 --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" }
|
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)"
|
& $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) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Log "Automatic fix failed; aborting." "ERROR"
|
|
||||||
exit 7
|
|
||||||
} else {
|
|
||||||
Write-Log "Success: urllib3 problems appear resolved; continuing." "INFO"
|
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 {
|
} else {
|
||||||
Write-Log "Aborting bootstrap to avoid leaving a broken environment." "ERROR"
|
Write-Log "Aborting bootstrap to avoid leaving a broken environment." "ERROR"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ FIX_URLLIB3=false
|
|||||||
# Playwright options
|
# Playwright options
|
||||||
PLAYWRIGHT_BROWSERS="chromium" # comma-separated (chromium,firefox,webkit) or 'all'
|
PLAYWRIGHT_BROWSERS="chromium" # comma-separated (chromium,firefox,webkit) or 'all'
|
||||||
NO_PLAYWRIGHT=false
|
NO_PLAYWRIGHT=false
|
||||||
|
REMOVE_PTH=false
|
||||||
|
|
||||||
attempt_fix_urllib3() {
|
attempt_fix_urllib3() {
|
||||||
local venv_py="$1"
|
local venv_py="$1"
|
||||||
@@ -53,6 +54,87 @@ attempt_fix_urllib3() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "ERROR: urllib3 fix attempt incomplete (import check failed)" >&2
|
echo "ERROR: urllib3 fix attempt incomplete (import check failed)" >&2
|
||||||
|
|
||||||
|
# Detect potential interfering .pth files in site-packages
|
||||||
|
echo "Searching for interfering .pth files in the venv site-packages..." >&2
|
||||||
|
local site_pkgs
|
||||||
|
site_pkgs=$("$venv_py" - <<'PY'
|
||||||
|
import json, site, sysconfig
|
||||||
|
paths = []
|
||||||
|
try:
|
||||||
|
paths.extend(site.getsitepackages())
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
p = sysconfig.get_paths().get('purelib')
|
||||||
|
if p:
|
||||||
|
paths.append(p)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
seen = []
|
||||||
|
out = []
|
||||||
|
for s in paths:
|
||||||
|
if s and s not in seen:
|
||||||
|
seen.append(s)
|
||||||
|
out.append(s)
|
||||||
|
print("\n".join(out))
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
local pths=()
|
||||||
|
if [[ -n "$site_pkgs" ]]; then
|
||||||
|
while IFS= read -r sp; do
|
||||||
|
if [[ -d "$sp" ]]; then
|
||||||
|
while IFS= read -r f; do
|
||||||
|
if [[ -n "$f" ]]; then
|
||||||
|
if grep -qi 'urllib3_future' "$f" >/dev/null 2>&1 || grep -qi 'urllib3-future' "$f" >/dev/null 2>&1; then
|
||||||
|
pths+=("$f")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < <(find "$sp" -maxdepth 1 -type f -name '*.pth' -print 2>/dev/null)
|
||||||
|
fi
|
||||||
|
done <<< "$site_pkgs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${#pths[@]} -eq 0 ]]; then
|
||||||
|
echo "No obvious interfering .pth files found in site-packages. Manual inspection recommended." >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Found the following potentially interfering .pth files:" >&2
|
||||||
|
for p in "${pths[@]}"; do echo " - $p" >&2; done
|
||||||
|
|
||||||
|
if [[ "$REMOVE_PTH" == "true" ]]; then
|
||||||
|
echo "Removing .pth files as requested..." >&2
|
||||||
|
for p in "${pths[@]}"; do rm -f "$p"; done
|
||||||
|
else
|
||||||
|
if [[ "$QUIET" == "true" ]]; then
|
||||||
|
echo "Detected interfering .pth files but cannot prompt in quiet mode. Re-run with --remove-pth to remove them automatically." >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
read -p "Remove these files now? (y/N) " resp
|
||||||
|
if [[ "$resp" != "y" && "$resp" != "Y" ]]; then
|
||||||
|
echo "User declined to remove .pth files. Aborting." >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
for p in "${pths[@]}"; do rm -f "$p"; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Re-run reinstall & verify
|
||||||
|
echo "Reinstalling urllib3 after .pth removal..." >&2
|
||||||
|
set +e
|
||||||
|
"$venv_py" -m pip install --upgrade --force-reinstall urllib3
|
||||||
|
local pip_ret2=$?
|
||||||
|
set -e
|
||||||
|
if [[ $pip_ret2 -ne 0 ]]; then
|
||||||
|
echo "ERROR: pip reinstall failed after .pth removal (exit $pip_ret2)" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
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 after .pth removal" >&2
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "ERROR: urllib3 still not importable after .pth removal" >&2
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +151,7 @@ Options:
|
|||||||
--playwright-browsers <list> Comma-separated list of browsers to install (default: 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
|
-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, --fix-urllib3 Attempt to automatically fix known urllib3 issues in the venv if detected
|
||||||
|
-R, --remove-pth When fixing urllib3, automatically remove interfering .pth files (like urllib3_future.pth)
|
||||||
-f, --force Overwrite existing venv without prompting
|
-f, --force Overwrite existing venv without prompting
|
||||||
-h, --help Show this help
|
-h, --help Show this help
|
||||||
EOF
|
EOF
|
||||||
@@ -83,6 +166,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
-n|--no-install) NOINSTALL=true; shift;;
|
-n|--no-install) NOINSTALL=true; shift;;
|
||||||
-f|--force) FORCE=true; shift;;
|
-f|--force) FORCE=true; shift;;
|
||||||
-F|--fix-urllib3) FIX_URLLIB3=true; shift;;
|
-F|--fix-urllib3) FIX_URLLIB3=true; shift;;
|
||||||
|
-R|--remove-pth) REMOVE_PTH=true; shift;;
|
||||||
-q|--quiet) QUIET=true; shift;;
|
-q|--quiet) QUIET=true; shift;;
|
||||||
-h|--help) usage; exit 0;;
|
-h|--help) usage; exit 0;;
|
||||||
--no-playwright) NO_PLAYWRIGHT=true; shift;;
|
--no-playwright) NO_PLAYWRIGHT=true; shift;;
|
||||||
|
|||||||
Reference in New Issue
Block a user