From 22a7c46d54f5c3b68cf811689a05ecac8e31d9a9 Mon Sep 17 00:00:00 2001 From: rockandska Date: Wed, 17 Sep 2025 02:53:37 +0200 Subject: [PATCH] upgrade pip detetcion in pip-rehash to accept multiple variations: (#3330) - pip - pipX - pipX.Y - * -m pip Co-authored-by: Christian Fredrik Johnsen --- pyenv.d/exec/pip-rehash.bash | 3 ++ test/pip-rehash.bats | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 test/pip-rehash.bats diff --git a/pyenv.d/exec/pip-rehash.bash b/pyenv.d/exec/pip-rehash.bash index f608f4ac..4f0f37ba 100644 --- a/pyenv.d/exec/pip-rehash.bash +++ b/pyenv.d/exec/pip-rehash.bash @@ -4,6 +4,9 @@ PYENV_REHASH_COMMAND="${PYENV_COMMAND##*/}" # Remove any version information, from e.g. "pip2" or "pip3.10". if [[ $PYENV_REHASH_COMMAND =~ ^(pip|easy_install)[23](\.[0-9]+)?$ ]]; then PYENV_REHASH_COMMAND="${BASH_REMATCH[1]}" +# Check for ` -m pip ` in arguments +elif [[ "$*" =~ [[:space:]]-m[[:space:]]pip[[:space:]] ]]; then + PYENV_REHASH_COMMAND="pip" fi if [ -x "${PYENV_PIP_REHASH_ROOT}/${PYENV_REHASH_COMMAND}" ]; then diff --git a/test/pip-rehash.bats b/test/pip-rehash.bats new file mode 100755 index 00000000..f5b065e6 --- /dev/null +++ b/test/pip-rehash.bats @@ -0,0 +1,67 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin" + mkdir -p "$bin" + echo "#!/bin/sh" > "${bin}/$1" + chmod +x "${bin}/$1" +} + +copy_src_pyenvd() { + mkdir -p "${PYENV_ROOT}" + cp -r "${BATS_TEST_DIRNAME}/../pyenv.d" "${PYENV_ROOT}" +} + +@test "pip-rehash triggered when using 'pip'" { + export PYENV_VERSION="3.7.14" + create_executable "example" + create_executable "pip" + copy_src_pyenvd + run command -v example 2> /dev/null + assert_failure + run pyenv-exec pip install example + assert_success + run command -v example 2> /dev/null + assert_success +} + +@test "pip-rehash triggered when using 'pip3'" { + export PYENV_VERSION="3.7.14" + create_executable "example" + create_executable "pip3" + copy_src_pyenvd + run command -v example 2> /dev/null + assert_failure + run pyenv-exec pip3 install example + assert_success + run command -v example 2> /dev/null + assert_success +} + +@test "pip-rehash triggered when using 'pip3.x'" { + export PYENV_VERSION="3.7.14" + create_executable "example" + create_executable "pip3.7" + copy_src_pyenvd + run command -v example 2> /dev/null + assert_failure + run pyenv-exec pip3.7 install example + assert_success + run command -v example 2> /dev/null + assert_success +} + +@test "pip-rehash triggered when using 'python -m pip install'" { + export PYENV_VERSION="3.7.14" + create_executable "example" + create_executable "python" + copy_src_pyenvd + run command -v example 2> /dev/null + assert_failure + run pyenv-exec python -m pip install example + assert_success + run command -v example 2> /dev/null + assert_success +}