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
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Resolve script path (follow symlinks if possible) and derive repo root dynamically
|
# REPO is injected at install time; if it doesn't look like a project, try to
|
||||||
SCRIPT="$0"
|
# find the repo by walking up from the current working directory.
|
||||||
if command -v readlink >/dev/null 2>&1; then
|
REPO="__REPO__"
|
||||||
if readlink -f "$SCRIPT" >/dev/null 2>&1; then
|
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ] && [ ! -f "$REPO/setup.py" ]; then
|
||||||
SCRIPT="$(readlink -f "$SCRIPT")"
|
CUR="$(pwd -P)"
|
||||||
fi
|
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
|
fi
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)"
|
|
||||||
REPO="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|
||||||
VENV="$REPO/.venv"
|
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
|
if [ -x "$VENV/bin/mm" ]; then
|
||||||
exec "$VENV/bin/mm" "$@"
|
exec "$VENV/bin/mm" "$@"
|
||||||
fi
|
fi
|
||||||
@@ -440,7 +445,7 @@ if [ -x "$VENV/bin/python" ]; then
|
|||||||
exec "$VENV/bin/python" -m medeia_macina.cli_entry "$@"
|
exec "$VENV/bin/python" -m medeia_macina.cli_entry "$@"
|
||||||
fi
|
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
|
if command -v python3 >/dev/null 2>&1; then
|
||||||
exec python3 -m medeia_macina.cli_entry "$@"
|
exec python3 -m medeia_macina.cli_entry "$@"
|
||||||
fi
|
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
|
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
|
exit 127
|
||||||
MM
|
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"
|
chmod +x "$USER_BIN/mm"
|
||||||
|
|
||||||
# Quick verification of the global launcher; helps catch packaging issues early.
|
# Quick verification of the global launcher; helps catch packaging issues early.
|
||||||
|
|||||||
@@ -363,14 +363,20 @@ python $cli @args
|
|||||||
sh_text = (
|
sh_text = (
|
||||||
"#!/usr/bin/env bash\n"
|
"#!/usr/bin/env bash\n"
|
||||||
"set -e\n"
|
"set -e\n"
|
||||||
"SCRIPT=\"$0\"\n"
|
f"REPO=\"{repo}\"\n"
|
||||||
"if command -v readlink >/dev/null 2>&1; then\n"
|
"# If the packaged REPO does not look valid at runtime, try to locate the repo by walking\n"
|
||||||
" if readlink -f \"$SCRIPT\" >/dev/null 2>&1; then\n"
|
"# up from the current working directory so the launcher works when executed inside the\n"
|
||||||
" SCRIPT=\"$(readlink -f \"$SCRIPT\")\"\n"
|
"# project tree or when the global bin is symlinked into the repo.\n"
|
||||||
" fi\n"
|
"if [ ! -f \"$REPO/CLI.py\" ] && [ ! -f \"$REPO/pyproject.toml\" ] && [ ! -f \"$REPO/setup.py\" ]; then\n"
|
||||||
|
" CUR=\"$(pwd -P)\"\n"
|
||||||
|
" while [ \"$CUR\" != \"/\" ] && [ \"$CUR\" != \"\" ]; do\n"
|
||||||
|
" if [ -f \"$CUR/CLI.py\" ] || [ -f \"$CUR/pyproject.toml\" ] || [ -f \"$CUR/setup.py\" ]; then\n"
|
||||||
|
" REPO=\"$CUR\"\n"
|
||||||
|
" break\n"
|
||||||
|
" fi\n"
|
||||||
|
" CUR=\"$(dirname \"$CUR\")\"\n"
|
||||||
|
" done\n"
|
||||||
"fi\n"
|
"fi\n"
|
||||||
"SCRIPT_DIR=\"$(cd \"$(dirname \"$SCRIPT\")\" && pwd -P)\"\n"
|
|
||||||
"REPO=\"$(cd \"$SCRIPT_DIR/..\" && pwd -P)\"\n"
|
|
||||||
"VENV=\"$REPO/.venv\"\n"
|
"VENV=\"$REPO/.venv\"\n"
|
||||||
"if [ -x \"$VENV/bin/mm\" ]; then\n"
|
"if [ -x \"$VENV/bin/mm\" ]; then\n"
|
||||||
" exec \"$VENV/bin/mm\" \"$@\"\n"
|
" exec \"$VENV/bin/mm\" \"$@\"\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user