bootstrap/setup: make global 'mm' wrapper prefer venv/python3 and fall back to python; include informative error when no Python found

This commit is contained in:
nose
2025-12-24 03:03:36 -08:00
parent 64aba67a31
commit 4cfe401eb3
2 changed files with 17 additions and 7 deletions

View File

@@ -412,16 +412,21 @@ if [[ -f "$USER_BIN/mm" ]]; then
echo "Backing up existing $USER_BIN/mm to $USER_BIN/mm.bak.$(date +%s)"
mv "$USER_BIN/mm" "$USER_BIN/mm.bak.$(date +%s)"
fi
cat > "$USER_BIN/mm" <<'EOF'
cat > "$USER_BIN/mm" <<EOF
#!/usr/bin/env bash
REPO="$REPO"
VENV="$REPO/.venv"
if [ -x "$VENV/bin/mm" ]; then
exec "$VENV/bin/mm" "$@"
exec "$VENV/bin/mm" "\$@"
elif [ -x "$VENV/bin/python" ]; then
exec "$VENV/bin/python" -m medeia_macina.cli_entry "$@"
exec "$VENV/bin/python" -m medeia_macina.cli_entry "\$@"
elif command -v python3 >/dev/null 2>&1; then
exec python3 -m medeia_macina.cli_entry "\$@"
elif command -v python >/dev/null 2>&1; then
exec python -m medeia_macina.cli_entry "\$@"
else
exec python -m medeia_macina.cli_entry "$@"
echo "Error: no Python interpreter found (python3 or python). Activate the venv with 'source $VENV/bin/activate' or install system Python 3." >&2
exit 127
fi
EOF
chmod +x "$USER_BIN/mm"

View File

@@ -363,13 +363,18 @@ python $cli @args
sh_text = (
"#!/usr/bin/env bash\n"
f"REPO=\"{repo}\"\n"
"VENV=\"$REPO/.venv\"\n"
f"VENV=\"{repo}/.venv\"\n"
"if [ -x \"$VENV/bin/mm\" ]; then\n"
" exec \"$VENV/bin/mm\" \"$@\"\n"
"elif [ -x \"$VENV/bin/python\" ]; then\n"
" exec \"$VENV/bin/python\" -m medeia_entry \"$@\"\n"
" exec \"$VENV/bin/python\" -m medeia_macina.cli_entry \"$@\"\n"
"elif command -v python3 >/dev/null 2>&1; then\n"
" exec python3 -m medeia_macina.cli_entry \"$@\"\n"
"elif command -v python >/dev/null 2>&1; then\n"
" exec python -m medeia_macina.cli_entry \"$@\"\n"
"else\n"
" exec python -m medeia_entry \"$@\"\n"
" echo 'Error: no Python interpreter (python3 or python) found in PATH. Please install Python 3 or use the venv.' >&2\n"
" exit 127\n"
"fi\n"
)
if mm_sh.exists():