installer: make 'mm' launcher determine repo/python at runtime and prefer venv's python3 before system python
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:
@@ -412,23 +412,47 @@ 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" <<'MM'
|
||||
#!/usr/bin/env bash
|
||||
REPO="$REPO"
|
||||
VENV="$REPO/.venv"
|
||||
if [ -x "$VENV/bin/mm" ]; then
|
||||
exec "$VENV/bin/mm" "\$@"
|
||||
elif [ -x "$VENV/bin/python" ]; then
|
||||
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
|
||||
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
|
||||
set -e
|
||||
|
||||
# Resolve script path (follow symlinks if possible) and derive repo root dynamically
|
||||
SCRIPT="$0"
|
||||
if command -v readlink >/dev/null 2>&1; then
|
||||
if readlink -f "$SCRIPT" >/dev/null 2>&1; then
|
||||
SCRIPT="$(readlink -f "$SCRIPT")"
|
||||
fi
|
||||
fi
|
||||
EOF
|
||||
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)"
|
||||
REPO="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||
VENV="$REPO/.venv"
|
||||
|
||||
# Prefer a packaged console script in the venv
|
||||
if [ -x "$VENV/bin/mm" ]; then
|
||||
exec "$VENV/bin/mm" "$@"
|
||||
fi
|
||||
|
||||
# Prefer venv's python3, then venv's python
|
||||
if [ -x "$VENV/bin/python3" ]; then
|
||||
exec "$VENV/bin/python3" -m medeia_macina.cli_entry "$@"
|
||||
fi
|
||||
if [ -x "$VENV/bin/python" ]; then
|
||||
exec "$VENV/bin/python" -m medeia_macina.cli_entry "$@"
|
||||
fi
|
||||
|
||||
# Fallback to system python3, then python (ensure python is v3)
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
exec python3 -m medeia_macina.cli_entry "$@"
|
||||
fi
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
if python -c 'import sys; sys.exit(0 if sys.version_info[0] >= 3 else 1)'; then
|
||||
exec python -m medeia_macina.cli_entry "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "Error: no suitable Python 3 interpreter found. Activate the venv with 'source %s/bin/activate' or install Python 3.\n" "$VENV" >&2
|
||||
exit 127
|
||||
MM
|
||||
chmod +x "$USER_BIN/mm"
|
||||
|
||||
# Quick verification of the global launcher; helps catch packaging issues early.
|
||||
|
||||
Reference in New Issue
Block a user