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

This commit is contained in:
nose
2025-12-24 02:13:21 -08:00
parent 8bf04c6b71
commit 24dd18de7e
20 changed files with 1792 additions and 636 deletions

View File

@@ -25,6 +25,8 @@ param(
[string]$Python = "",
[switch]$Force,
[switch]$NoInstall,
[switch]$NoPlaywright,
[string]$PlaywrightBrowsers = "chromium",
[switch]$Quiet
)
@@ -146,17 +148,56 @@ if (-not $NoInstall) {
} catch {
Write-Log "pip install failed: $_" "ERROR"; exit 6
}
} else {
Write-Log "Skipping install (--NoInstall set)"
}
# Install Deno (official installer) - installed automatically
try {
$denoCmd = Get-Command 'deno' -ErrorAction SilentlyContinue
} catch {
$denoCmd = $null
}
if ($denoCmd) {
# Install Playwright browsers (default: chromium) unless explicitly disabled
if (-not $NoPlaywright) {
Write-Log "Ensuring Playwright browsers are installed (browsers=$PlaywrightBrowsers)..."
try {
& $venvPython -c "import importlib; importlib.import_module('playwright')" 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Log "'playwright' package not found in venv; installing via pip..."
& $venvPython -m pip install playwright
}
} catch {
Write-Log "Failed to check/install 'playwright' package: $_" "ERROR"
}
try {
if ($PlaywrightBrowsers -eq 'all') {
Write-Log "Installing all Playwright browsers..."
& $venvPython -m playwright install
} else {
$list = $PlaywrightBrowsers -split ','
foreach ($b in $list) {
$btrim = $b.Trim()
if ($btrim) {
Write-Log "Installing Playwright browser: $btrim"
& $venvPython -m playwright install $btrim
}
}
}
} catch {
Write-Log "Playwright browser install failed: $_" "ERROR"
}
}
# Verify environment for known package conflicts (urllib3 compatibility)
Write-Log "Verifying environment for known package conflicts (urllib3 compatibility)..."
try {
& $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 "Bootstrap detected a potentially broken 'urllib3' installation. See message above." "ERROR"
Write-Log "Suggested fixes (activate the venv first):" "INFO"
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"
Write-Log "Aborting bootstrap to avoid leaving a broken environment." "ERROR"
exit 7
}
} catch {
Write-Log "Failed to run environment verification: $_" "ERROR"
}
Write-Log "Deno is already installed: $($denoCmd.Path)"
} else {
Write-Log "Installing Deno via official installer (https://deno.land)"
@@ -242,12 +283,12 @@ try {
$cmdText = @"
@echo off
set "REPO=__REPO__"
if exist "%REPO%\.venv\Scripts\mm.exe" (
"%REPO%\.venv\Scripts\mm.exe" %*
if exist "%REPO%\.venv\Scripts\python.exe" (
"%REPO%\.venv\Scripts\python.exe" "%REPO%\CLI.py" %*
exit /b %ERRORLEVEL%
)
if exist "%REPO%\.venv\Scripts\python.exe" (
"%REPO%\.venv\Scripts\python.exe" -m medeia_macina.cli_entry %*
if exist "%REPO%\CLI.py" (
python "%REPO%\CLI.py" %*
exit /b %ERRORLEVEL%
)
python -m medeia_macina.cli_entry %*
@@ -266,12 +307,12 @@ python -m medeia_macina.cli_entry %*
Param([Parameter(ValueFromRemainingArguments=$true)] $args)
$repo = "__REPO__"
$venv = Join-Path $repo '.venv'
$exe = Join-Path $venv 'Scripts\mm.exe'
if (Test-Path $exe) { & $exe @args; exit $LASTEXITCODE }
$py = Join-Path $venv 'Scripts\python.exe'
if (Test-Path $py) { & $py -m medeia_entry @args; exit $LASTEXITCODE }
$cli = Join-Path $repo 'CLI.py'
if (Test-Path $py) { & $py $cli @args; exit $LASTEXITCODE }
if (Test-Path $cli) { & $py $cli @args; exit $LASTEXITCODE }
# fallback
python -m medeia_entry @args
python $cli @args
'@
# Inject the actual repo path safely (escape embedded double-quotes if any)
$ps1Text = $ps1Text.Replace('__REPO__', $repo.Replace('"', '""'))

View File

@@ -9,6 +9,10 @@ DESKTOP=false
PYTHON_CMD=""
NOINSTALL=false
FORCE=false
QUIET=false
# Playwright options
PLAYWRIGHT_BROWSERS="chromium" # comma-separated (chromium,firefox,webkit) or 'all'
NO_PLAYWRIGHT=false
usage() {
cat <<EOF
@@ -19,6 +23,9 @@ Options:
--python <python> Python executable to use (e.g. python3)
-d, --desktop Create a desktop launcher (~/.local/share/applications and ~/Desktop)
-n, --no-install Skip pip install
--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, --force Overwrite existing venv without prompting
-h, --help Show this help
EOF
@@ -32,7 +39,10 @@ while [[ $# -gt 0 ]]; do
-d|--desktop) DESKTOP=true; shift;;
-n|--no-install) NOINSTALL=true; shift;;
-f|--force) FORCE=true; shift;;
-q|--quiet) QUIET=true; shift;;
-h|--help) usage; exit 0;;
--no-playwright) NO_PLAYWRIGHT=true; shift;;
--playwright-browsers) PLAYWRIGHT_BROWSERS="$2"; shift 2;;
*) echo "Unknown option: $1"; usage; exit 1;;
esac
done
@@ -51,21 +61,52 @@ fi
echo "Using Python: $PY"
if [[ -d "$VENV_PATH" ]]; then
# Detect whether the existing venv has a working python executable
VENV_PY=""
for cand in "$VENV_PATH/bin/python" "$VENV_PATH/bin/python3" "$VENV_PATH/Scripts/python.exe"; do
if [[ -x "$cand" ]]; then
VENV_PY="$cand"
break
fi
done
if [[ "$FORCE" == "true" ]]; then
echo "Removing existing venv $VENV_PATH"
rm -rf "$VENV_PATH"
else
read -p "$VENV_PATH already exists. Overwrite? [y/N] " REPLY
if [[ "$REPLY" != "y" && "$REPLY" != "Y" ]]; then
echo "Aborted."; exit 0
if [[ -z "$VENV_PY" ]]; then
if [[ "$QUIET" == "true" ]]; then
echo "ERROR: Existing venv appears incomplete or broken (no python executable). Use --force to recreate." >&2
exit 4
fi
read -p "$VENV_PATH exists but appears invalid (no python executable). Overwrite to recreate? (y/N) " REPLY
if [[ "$REPLY" != "y" && "$REPLY" != "Y" ]]; then
echo "Aborted."; exit 4
fi
rm -rf "$VENV_PATH"
else
if [[ "$QUIET" == "true" ]]; then
echo "Using existing venv at $VENV_PATH (quiet mode)"
else
read -p "$VENV_PATH already exists. Overwrite? (y/N) (default: use existing venv) " REPLY
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
echo "Removing existing venv $VENV_PATH"
rm -rf "$VENV_PATH"
else
echo "Continuing using existing venv at $VENV_PATH"
fi
fi
fi
rm -rf "$VENV_PATH"
fi
fi
echo "Creating venv at $VENV_PATH"
$PY -m venv "$VENV_PATH"
VENV_PY="$VENV_PATH/bin/python"
if [[ -d "$VENV_PATH" && -n "${VENV_PY:-}" && -x "${VENV_PY:-}" ]]; then
echo "Using existing venv at $VENV_PATH"
else
echo "Creating venv at $VENV_PATH"
$PY -m venv "$VENV_PATH"
VENV_PY="$VENV_PATH/bin/python"
fi
if [[ ! -x "$VENV_PY" ]]; then
echo "ERROR: venv python not found at $VENV_PY" >&2
@@ -98,6 +139,41 @@ if [[ "$NOINSTALL" != "true" ]]; then
echo "Action: Try running: $VENV_PY -m pip install -e . or inspect the venv site-packages to verify the installation." >&2
fi
fi
echo "Verifying environment for known issues (urllib3 compatibility)..."
if ! "$VENV_PY" -c 'from SYS.env_check import check_urllib3_compat; ok,msg = check_urllib3_compat(); print(msg); import sys; sys.exit(0 if ok else 2)'; then
echo "ERROR: Bootstrap detected a potentially broken 'urllib3' installation. See message above." >&2
echo "You can attempt to fix with:" >&2
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
exit 7
fi
# Install Playwright browsers (default: chromium) unless explicitly disabled
if [[ "$NO_PLAYWRIGHT" != "true" && "$NOINSTALL" != "true" ]]; then
echo "Ensuring Playwright browsers are installed (browsers=$PLAYWRIGHT_BROWSERS)..."
# Install package if missing in venv
if ! "$VENV_PY" -c 'import importlib, sys; importlib.import_module("playwright")' >/dev/null 2>&1; then
echo "'playwright' package not found in venv; installing via pip..."
"$VENV_PY" -m pip install playwright
fi
# Compute install behavior: 'all' means install all engines, otherwise split comma list
if [[ "$PLAYWRIGHT_BROWSERS" == "all" ]]; then
echo "Installing all Playwright browsers..."
"$VENV_PY" -m playwright install || echo "Warning: Playwright browser install failed" >&2
else
IFS=',' read -ra PWB <<< "$PLAYWRIGHT_BROWSERS"
for b in "${PWB[@]}"; do
b_trimmed=$(echo "$b" | tr -d '[:space:]')
if [[ -n "$b_trimmed" ]]; then
echo "Installing Playwright browser: $b_trimmed"
"$VENV_PY" -m playwright install "$b_trimmed" || echo "Warning: Playwright install for $b_trimmed failed" >&2
fi
done
fi
fi
else
echo "Skipping install (--no-install)"
fi
@@ -139,7 +215,7 @@ if [[ "$DESKTOP" == "true" ]]; then
Name=Medeia-Macina
Comment=Launch Medeia-Macina
Exec=$EXEC_PATH
Terminal=true
Terminal=false
Type=Application
Categories=Utility;
EOF

View File

@@ -251,13 +251,14 @@ def main() -> int:
sh_text = """#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV="$SCRIPT_DIR/.venv"
if [ -x "$VENV/bin/mm" ]; then
exec "$VENV/bin/mm" "$@"
elif [ -x "$VENV/bin/python" ]; then
exec "$VENV/bin/python" -m medeia_entry "$@"
REPO="$SCRIPT_DIR"
VENV="$REPO/.venv"
PY="$VENV/bin/python"
CLI_SCRIPT="$REPO/CLI.py"
if [ -x "$PY" ]; then
exec "$PY" "$CLI_SCRIPT" "$@"
else
exec python -m medeia_entry "$@"
exec python "$CLI_SCRIPT" "$@"
fi
"""
try:
@@ -268,13 +269,14 @@ fi
ps1_text = r"""Param([Parameter(ValueFromRemainingArguments=$true)] $args)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$venv = Join-Path $scriptDir '.venv'
$exe = Join-Path $venv 'Scripts\mm.exe'
if (Test-Path $exe) { & $exe @args; exit $LASTEXITCODE }
$repo = $scriptDir
$venv = Join-Path $repo '.venv'
$py = Join-Path $venv 'Scripts\python.exe'
if (Test-Path $py) { & $py -m medeia_entry @args; exit $LASTEXITCODE }
$cli = Join-Path $repo 'CLI.py'
if (Test-Path $py) { & $py $cli @args; exit $LASTEXITCODE }
if (Test-Path $cli) { & $py $cli @args; exit $LASTEXITCODE }
# fallback
python -m medeia_entry @args
python $cli @args
"""
try:
ps1.write_text(ps1_text, encoding="utf-8")
@@ -284,9 +286,9 @@ python -m medeia_entry @args
bat_text = (
"@echo off\r\n"
"set SCRIPT_DIR=%~dp0\r\n"
"if exist \"%SCRIPT_DIR%\\.venv\\Scripts\\mm.exe\" \"%SCRIPT_DIR%\\.venv\\Scripts\\mm.exe\" %*\r\n"
"if exist \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" -m medeia_entry %*\r\n"
"python -m medeia_entry %*\r\n"
"if exist \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\CLI.py\" %*\r\n"
"if exist \"%SCRIPT_DIR%\\CLI.py\" python \"%SCRIPT_DIR%\\CLI.py\" %*\r\n"
"python -m medeia_macina.cli_entry %*\r\n"
)
try:
bat.write_text(bat_text, encoding="utf-8")