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

This commit is contained in:
nose
2025-12-24 05:23:39 -08:00
parent 892fe1cb0a
commit 3ab96325cc

View File

@@ -30,7 +30,27 @@ PLAYWRIGHT_BROWSERS="chromium" # comma-separated (chromium,firefox,webkit) or
NO_PLAYWRIGHT=false
REMOVE_PTH=false
attempt_fix_urllib3() {
# Prompt helper: read from the controlling terminal so prompts still work
# when stdout/stderr are redirected or piped (e.g., piping output to sed).
prompt_yes_no() {
local prompt="$1"
local default="${2:-n}"
local answer
if [[ "${QUIET:-false}" == "true" ]]; then
answer="$default"
else
if [[ -t 0 ]]; then
read -r -p "$prompt" answer
elif [[ -e /dev/tty ]]; then
read -r -p "$prompt" answer < /dev/tty
else
answer="$default"
fi
fi
echo "$answer"
}
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
@@ -114,7 +134,7 @@ PY
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
resp="$(prompt_yes_no 'Remove these files now? (y/N) ' 'n')"
if [[ "$resp" != "y" && "$resp" != "Y" ]]; then
echo "User declined to remove .pth files. Aborting." >&2
return 3
@@ -205,6 +225,35 @@ if ! cd "$REPO"; then
fi
echo "Operating from repo root: $REPO"
# If running as root (via sudo), warn the user because bootstrap will create files
# in the repo that may end up owned by root (e.g., the .venv directory).
if [[ "$EUID" -eq 0 ]]; then
echo "WARNING: Running bootstrap as root. This may create files owned by root (e.g., .venv). Consider running without sudo unless you intend system-level installs." >&2
fi
# Basic sanity check: ensure the detected repo root actually looks like the project
if [[ ! -f "$REPO/pyproject.toml" && ! -f "$REPO/setup.py" && ! -f "$REPO/CLI.py" ]]; then
echo "WARNING: Detected repo root ($REPO) does not contain pyproject.toml, setup.py, or CLI.py; attempting to locate project root via git or current working directory..." >&2
if git -C "$SCRIPT_DIR/.." rev-parse --show-toplevel >/dev/null 2>&1; then
REPO="$(git -C "$SCRIPT_DIR/.." rev-parse --show-toplevel)"
if ! cd "$REPO"; then
echo "ERROR: Failed to change to repo root: $REPO" >&2
exit 2
fi
echo "Operating from repo root (detected via git): $REPO"
elif git -C "$PWD" rev-parse --show-toplevel >/dev/null 2>&1; then
REPO="$(git -C "$PWD" rev-parse --show-toplevel)"
if ! cd "$REPO"; then
echo "ERROR: Failed to change to repo root: $REPO" >&2
exit 2
fi
echo "Operating from repo root (detected via current working dir): $REPO"
else
echo "ERROR: Could not determine the project root. Please run the script from the project root or supply --repo <path>." >&2
exit 2
fi
fi
if [[ -d "$VENV_PATH" ]]; then
# Detect whether the existing venv has a working python executable
VENV_PY=""
@@ -224,7 +273,7 @@ if [[ -d "$VENV_PATH" ]]; 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
REPLY="$(prompt_yes_no "$VENV_PATH exists but appears invalid (no python executable). Overwrite to recreate? (y/N) " 'n')"
if [[ "$REPLY" != "y" && "$REPLY" != "Y" ]]; then
echo "Aborted."; exit 4
fi
@@ -233,7 +282,7 @@ if [[ -d "$VENV_PATH" ]]; then
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
REPLY="$(prompt_yes_no "$VENV_PATH already exists. Overwrite? (y/N) (default: use existing venv) " 'n')"
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
echo "Removing existing venv $VENV_PATH"
rm -rf "$VENV_PATH"
@@ -362,7 +411,7 @@ PY
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
REPLY="$(prompt_yes_no 'Attempt automatic fix now? (y/N) ' 'n')"
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
AUTOFIX_INTERACTIVE=1
if attempt_fix_urllib3 "$VENV_PY"; then