installer: embed repo path in global 'mm' launcher and fall back to locating repo from CWD; prefer venv's python3
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:
@@ -416,18 +416,23 @@ cat > "$USER_BIN/mm" <<'MM'
|
||||
#!/usr/bin/env bash
|
||||
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
|
||||
# REPO is injected at install time; if it doesn't look like a project, try to
|
||||
# find the repo by walking up from the current working directory.
|
||||
REPO="__REPO__"
|
||||
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ] && [ ! -f "$REPO/setup.py" ]; then
|
||||
CUR="$(pwd -P)"
|
||||
while [ "$CUR" != "/" ] && [ "$CUR" != "" ]; do
|
||||
if [ -f "$CUR/CLI.py" ] || [ -f "$CUR/pyproject.toml" ] || [ -f "$CUR/setup.py" ]; then
|
||||
REPO="$CUR"
|
||||
break
|
||||
fi
|
||||
CUR="$(dirname "$CUR")"
|
||||
done
|
||||
fi
|
||||
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)"
|
||||
REPO="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||
|
||||
VENV="$REPO/.venv"
|
||||
|
||||
# Prefer a packaged console script in the venv
|
||||
# Packaged console script in the venv if available
|
||||
if [ -x "$VENV/bin/mm" ]; then
|
||||
exec "$VENV/bin/mm" "$@"
|
||||
fi
|
||||
@@ -440,7 +445,7 @@ 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)
|
||||
# Fallback to system python3, then system python (only if it's Python 3)
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
exec python3 -m medeia_macina.cli_entry "$@"
|
||||
fi
|
||||
@@ -453,6 +458,10 @@ 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
|
||||
|
||||
# Inject absolute repo path into the installed script so global launcher prefers the project venv
|
||||
escaped_repo=$(printf '%s' "$REPO" | sed -e 's/[\/&]/\\&/g')
|
||||
sed -i "s|__REPO__|$escaped_repo|g" "$USER_BIN/mm" || true
|
||||
chmod +x "$USER_BIN/mm"
|
||||
|
||||
# Quick verification of the global launcher; helps catch packaging issues early.
|
||||
|
||||
Reference in New Issue
Block a user