hjh
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:
@@ -474,31 +474,31 @@ set -e
|
|||||||
|
|
||||||
# REPO is injected at install time; try to resolve canonical project root using
|
# REPO is injected at install time; try to resolve canonical project root using
|
||||||
# git when available to avoid mistakenly selecting parent directories.
|
# 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__"
|
REPO="__REPO__"
|
||||||
if command -v git >/dev/null 2>&1; then
|
# If the placeholder does not appear to point at a repo, attempt discovery.
|
||||||
gitroot=$(git -C "$REPO" rev-parse --show-toplevel 2>/dev/null || true)
|
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then
|
||||||
if [ -n "$gitroot" ]; then
|
# First try to find a git toplevel from the current working directory.
|
||||||
REPO="$gitroot"
|
if command -v git >/dev/null 2>&1; then
|
||||||
else
|
|
||||||
# Try resolving from the current working directory
|
|
||||||
gitroot=$(git -C "$(pwd -P)" rev-parse --show-toplevel 2>/dev/null || true)
|
gitroot=$(git -C "$(pwd -P)" rev-parse --show-toplevel 2>/dev/null || true)
|
||||||
if [ -n "$gitroot" ]; then
|
if [ -n "$gitroot" ]; then
|
||||||
REPO="$gitroot"
|
REPO="$gitroot"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback: walk up from CWD to find CLI.py or pyproject.toml
|
|
||||||
if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then
|
|
||||||
CUR="$(pwd -P)"
|
|
||||||
while [ "$CUR" != "/" ] && [ "$CUR" != "" ]; do
|
|
||||||
if [ -f "$CUR/CLI.py" ] || [ -f "$CUR/pyproject.toml" ]; then
|
|
||||||
REPO="$CUR"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
CUR="$(dirname "$CUR")"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
fi
|
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
|
||||||
|
if [ -f "$CUR/CLI.py" ] || [ -f "$CUR/pyproject.toml" ]; then
|
||||||
|
REPO="$CUR"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
CUR="$(dirname "$CUR")"
|
||||||
|
done
|
||||||
|
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"
|
VENV="$REPO/.venv"
|
||||||
|
|
||||||
@@ -565,10 +565,30 @@ exit 127
|
|||||||
MM
|
MM
|
||||||
|
|
||||||
# Inject absolute repo path into the installed script so global launcher prefers the project venv
|
# Inject absolute repo path into the installed script so global launcher prefers the project venv
|
||||||
escaped_repo=$(printf '%s' "$REPO" | sed -e 's/[\/&]/\\&/g')
|
# Replace __REPO__ placeholder robustly using Python (preferred) else fallback to sed
|
||||||
sed -i "s|__REPO__|$escaped_repo|g" "$USER_BIN/mm" || true
|
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"
|
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.
|
# Quick verification of the global launcher; helps catch packaging issues early.
|
||||||
if "$USER_BIN/mm" --help >/dev/null 2>&1; then
|
if "$USER_BIN/mm" --help >/dev/null 2>&1; then
|
||||||
echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly."
|
echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly."
|
||||||
|
|||||||
Reference in New Issue
Block a user