diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index aecf8bb..68f26c4 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -316,6 +316,15 @@ PY if "$VENV_PY" -c 'import importlib; importlib.import_module("CLI")' >/dev/null 2>&1; then echo "OK: top-level 'CLI' is now importable (after .pth)." >&2 + + # Also verify we can run the packaged entrypoint using module form. If this fails + # it suggests site-packages/.pth wasn't processed reliably by the interpreter. + if "$VENV_PY" -m medeia_macina.cli_entry --help >/dev/null 2>&1; then + echo "OK: 'python -m medeia_macina.cli_entry' runs in the venv." >&2 + else + echo "ERROR: 'python -m medeia_macina.cli_entry' failed in the venv despite .pth being written; aborting." >&2 + exit 6 + fi else echo "ERROR: top-level 'CLI' still not importable after writing .pth ($pth_file)." >&2 exit 6 @@ -528,12 +537,7 @@ PY echo "MM_DEBUG: end diagnostics" >&2 fi -# Packaged console script in the venv if available -if [ -x "$VENV/bin/mm" ]; then - exec "$VENV/bin/mm" "$@" -fi - -# Prefer venv's python3, then venv's python +# Prefer venv's python3, then venv's python (module invocation - more deterministic) if [ -x "$VENV/bin/python3" ]; then exec "$VENV/bin/python3" -m medeia_macina.cli_entry "$@" fi @@ -541,6 +545,11 @@ if [ -x "$VENV/bin/python" ]; then exec "$VENV/bin/python" -m medeia_macina.cli_entry "$@" fi +# Fallback: packaged console script in the venv (older pip-generated wrapper) +if [ -x "$VENV/bin/mm" ]; then + exec "$VENV/bin/mm" "$@" +fi + # 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 "$@" diff --git a/scripts/setup.py b/scripts/setup.py index 2d09b23..a698eac 100644 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -304,11 +304,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO="$SCRIPT_DIR" VENV="$REPO/.venv" PY="$VENV/bin/python" -CLI_SCRIPT="$REPO/CLI.py" if [ -x "$PY" ]; then - exec "$PY" "$CLI_SCRIPT" "$@" + exec "$PY" -m medeia_macina.cli_entry "$@" else - exec python "$CLI_SCRIPT" "$@" + exec python -m medeia_macina.cli_entry "$@" fi """ try: @@ -323,10 +322,10 @@ $repo = $scriptDir $venv = Join-Path $repo '.venv' $py = Join-Path $venv 'Scripts\python.exe' $cli = Join-Path $repo 'CLI.py' -if (Test-Path $py) { & $py $cli @args; exit $LASTEXITCODE } -if (Test-Path $cli) { & $py $cli @args; exit $LASTEXITCODE } +if (Test-Path $py) { & $py -m medeia_macina.cli_entry @args; exit $LASTEXITCODE } +if (Test-Path $cli) { & python $cli @args; exit $LASTEXITCODE } # fallback -python $cli @args +python -m medeia_macina.cli_entry @args """ try: ps1.write_text(ps1_text, encoding="utf-8") @@ -336,9 +335,10 @@ python $cli @args bat_text = ( "@echo off\r\n" "set SCRIPT_DIR=%~dp0\r\n" - "if exist \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\CLI.py\" %*\r\n" + "if exist \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" \"%SCRIPT_DIR%\\.venv\\Scripts\\python.exe\" -m medeia_macina.cli_entry %*\r\n" "if exist \"%SCRIPT_DIR%\\CLI.py\" python \"%SCRIPT_DIR%\\CLI.py\" %*\r\n" "python -m medeia_macina.cli_entry %*\r\n" + "python -m medeia_macina.cli_entry %*\r\n" ) try: bat.write_text(bat_text, encoding="utf-8")