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

This commit is contained in:
nose
2025-12-24 03:06:16 -08:00
parent 4cfe401eb3
commit 2208fdad96
2 changed files with 65 additions and 26 deletions

View File

@@ -362,20 +362,35 @@ python $cli @args
mm_sh = user_bin / "mm"
sh_text = (
"#!/usr/bin/env bash\n"
f"REPO=\"{repo}\"\n"
f"VENV=\"{repo}/.venv\"\n"
"set -e\n"
"SCRIPT=\"$0\"\n"
"if command -v readlink >/dev/null 2>&1; then\n"
" if readlink -f \"$SCRIPT\" >/dev/null 2>&1; then\n"
" SCRIPT=\"$(readlink -f \"$SCRIPT\")\"\n"
" fi\n"
"fi\n"
"SCRIPT_DIR=\"$(cd \"$(dirname \"$SCRIPT\")\" && pwd -P)\"\n"
"REPO=\"$(cd \"$SCRIPT_DIR/..\" && pwd -P)\"\n"
"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_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"
" 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 [ -x \"$VENV/bin/python3\" ]; then\n"
" exec \"$VENV/bin/python3\" -m medeia_macina.cli_entry \"$@\"\n"
"fi\n"
"if [ -x \"$VENV/bin/python\" ]; then\n"
" exec \"$VENV/bin/python\" -m medeia_macina.cli_entry \"$@\"\n"
"fi\n"
"if command -v python3 >/dev/null 2>&1; then\n"
" exec python3 -m medeia_macina.cli_entry \"$@\"\n"
"fi\n"
"if command -v python >/dev/null 2>&1; then\n"
" if python -c 'import sys; sys.exit(0 if sys.version_info[0] >= 3 else 1)'; then\n"
" exec python -m medeia_macina.cli_entry \"$@\"\n"
" fi\n"
"fi\n"
"echo 'Error: no suitable Python 3 interpreter found. Please install Python 3 or use the venv.' >&2\n"
"exit 127\n"
)
if mm_sh.exists():
bak = mm_sh.with_suffix(f".bak{int(time.time())}")