Skeleton for CI support

This commit is contained in:
Reinier Criel 2025-11-04 13:29:31 -08:00
parent 18f30ac66e
commit 6241c56fda
5 changed files with 316 additions and 11 deletions

View file

@ -0,0 +1,31 @@
#!/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

@ -0,0 +1,39 @@
@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
if "%1"=="-m" (
if /I "%2"=="pip3" (
shift
shift
set "PATH=%CLEAN_PATH%" & aikido-pip3 %*
goto :eof
)
if /I "%2"=="pip" (
shift
shift
if /I "%INVOKED%"=="python3" (
set "PATH=%CLEAN_PATH%" & aikido-pip3 %*
) else (
set "PATH=%CLEAN_PATH%" & aikido-pip %*
)
goto :eof
)
)
REM Fallback to real python/python3 matching the invoked name
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