This commit is contained in:
Reinier Criel 2025-11-06 08:32:25 -08:00
parent fa4c46c23d
commit f400c5576a
12 changed files with 59 additions and 213 deletions

View file

@ -1,31 +0,0 @@
#!/bin/sh
# Generated wrapper for python/python3 by safe-chain
# Intercepts `python[3] -m pip[...]` in CI environments
# Function to remove shim from PATH (POSIX-compliant)
remove_shim_from_path() {
echo "$PATH" | sed "s|$HOME/.safe-chain/shims:||g"
}
# Determine which python variant we were invoked as based on the script name
invoked=$(basename "$0")
# If invoked as `python -m pip[...]` or `python3 -m pip[...]`, route to aikido
if [ "$1" = "-m" ] && [ -n "$2" ] && echo "$2" | grep -Eq '^pip(3)?$'; then
mod="$2"
shift 2
if [ "$invoked" = "python3" ] || [ "$mod" = "pip3" ]; then
PATH=$(remove_shim_from_path) exec aikido-pip3 "$@"
else
PATH=$(remove_shim_from_path) exec aikido-pip "$@"
fi
fi
# Otherwise, find and exec the real python/python3 matching the invoked name
original_cmd=$(PATH=$(remove_shim_from_path) command -v "$invoked")
if [ -n "$original_cmd" ]; then
exec "$original_cmd" "$@"
else
echo "Error: Could not find original $invoked" >&2
exit 1
fi

View file

@ -7,6 +7,8 @@ remove_shim_from_path() {
echo "$PATH" | sed "s|$HOME/.safe-chain/shims:||g"
}
echo "[safe-chain debug] command -v {{AIKIDO_COMMAND}} (raw PATH): $(command -v {{AIKIDO_COMMAND}} 2>/dev/null || echo notfound)" >&2
echo "[safe-chain debug] PATH (raw): $PATH" >&2
if command -v {{AIKIDO_COMMAND}} >/dev/null 2>&1; then
# Remove shim directory from PATH when calling {{AIKIDO_COMMAND}} to prevent infinite loops
PATH=$(remove_shim_from_path) exec {{AIKIDO_COMMAND}} "$@"
@ -19,4 +21,4 @@ else
echo "Error: Could not find original {{PACKAGE_MANAGER}}" >&2
exit 1
fi
fi
fi

View file

@ -1,44 +0,0 @@
@echo off
REM Generated wrapper for python/python3 by safe-chain
REM Intercepts `python[3] -m pip[...]` in CI environments
REM Remove shim directory from PATH to prevent infinite loops
set "SHIM_DIR=%USERPROFILE%\.safe-chain\shims"
call set "CLEAN_PATH=%%PATH:%SHIM_DIR%;=%%"
REM Determine invoked name (python or python3) from the script name
set "INVOKED=%~n0"
REM Check for -m pip or -m pip3 without parentheses to avoid parser issues
if /I "%1" NEQ "-m" goto FALLBACK
set "SECOND=%2"
if /I "%SECOND%"=="pip3" goto CALL_PIP3
if /I "%SECOND%"=="pip" goto CALL_PIP
goto FALLBACK
:CALL_PIP3
shift
shift
set "PATH=%CLEAN_PATH%" & aikido-pip3 %1 %2 %3 %4 %5 %6 %7 %8 %9
goto :eof
:CALL_PIP
shift
shift
if /I "%INVOKED%"=="python3" (
set "PATH=%CLEAN_PATH%" & aikido-pip3 %1 %2 %3 %4 %5 %6 %7 %8 %9
) else (
set "PATH=%CLEAN_PATH%" & aikido-pip %1 %2 %3 %4 %5 %6 %7 %8 %9
)
goto :eof
REM Fallback to real python/python3 matching the invoked name
:FALLBACK
for /f "tokens=*" %%i in ('set "PATH=%CLEAN_PATH%" ^& where %INVOKED% 2^>nul') do (
"%%i" %*
goto :eof
)
echo Error: Could not find original %INVOKED% 1>&2
exit /b 1