hjh
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
nose
2025-12-24 04:48:04 -08:00
parent 5dc4a5ad67
commit 8e3cf7594e

View File

@@ -474,20 +474,20 @@ set -e
# REPO is injected at install time; try to resolve canonical project root using
# git when available to avoid mistakenly selecting parent directories.
# Try to locate the repo root dynamically. Use the embedded __REPO__ value as a hint,
# but prefer to discover a repo from the current working directory or git.
REPO="__REPO__"
# If the placeholder does not appear to point at a repo, attempt discovery.
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then
# First try to find a git toplevel from the current working directory.
if command -v git >/dev/null 2>&1; then
gitroot=$(git -C "$REPO" rev-parse --show-toplevel 2>/dev/null || true)
if [ -n "$gitroot" ]; then
REPO="$gitroot"
else
# Try resolving from the current working directory
gitroot=$(git -C "$(pwd -P)" rev-parse --show-toplevel 2>/dev/null || true)
if [ -n "$gitroot" ]; then
REPO="$gitroot"
fi
fi
else
# Fallback: walk up from CWD to find CLI.py or pyproject.toml
fi
# If still unresolved, walk up from the CWD looking for signs of the project.
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then
CUR="$(pwd -P)"
while [ "$CUR" != "/" ] && [ "$CUR" != "" ]; do
@@ -498,7 +498,7 @@ else
CUR="$(dirname "$CUR")"
done
fi
fi
# At this point REPO may still be wrong if mm was invoked outside any project; keep the embedded path as a last resort.
VENV="$REPO/.venv"
@@ -565,10 +565,30 @@ exit 127
MM
# Inject absolute repo path into the installed script so global launcher prefers the project venv
# Replace __REPO__ placeholder robustly using Python (preferred) else fallback to sed
if command -v python >/dev/null 2>&1; then
python - <<PY "$USER_BIN/mm" "$REPO"
import sys
fn=sys.argv[1]; repo=sys.argv[2]
with open(fn,'r', encoding='utf-8') as f:
s = f.read()
s = s.replace('__REPO__', repo)
with open(fn,'w', encoding='utf-8') as f:
f.write(s)
PY
else
escaped_repo=$(printf '%s' "$REPO" | sed -e 's/[\/&]/\\&/g')
sed -i "s|__REPO__|$escaped_repo|g" "$USER_BIN/mm" || true
fi
chmod +x "$USER_BIN/mm"
# Verify injection succeeded
if grep -Fq "$REPO" "$USER_BIN/mm"; then
echo "Installed global 'mm' launcher with REPO=$REPO"
else
echo "ERROR: failed to inject repository path into $USER_BIN/mm; inspect file: $USER_BIN/mm" >&2
fi
# Quick verification of the global launcher; helps catch packaging issues early.
if "$USER_BIN/mm" --help >/dev/null 2>&1; then
echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly."