From 26134d9b3862f7ec314a93a2c86f65ba3784d397 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Wed, 15 Sep 2021 19:07:00 +0300 Subject: [PATCH] Allow system Python in sbin Arch Linux has Python is sbin as well as bin --- libexec/pyenv-prefix | 4 +++- test/prefix.bats | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libexec/pyenv-prefix b/libexec/pyenv-prefix index 9e20a21a..9cd0715d 100755 --- a/libexec/pyenv-prefix +++ b/libexec/pyenv-prefix @@ -33,7 +33,9 @@ OLDIFS="$IFS" if PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python 2>/dev/null)" || \ PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python3 2>/dev/null)" || \ PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python2 2>/dev/null)"; then - PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" + shopt -s extglob + # In some distros (Arch), Python can be found in sbin as well as bin + PYENV_PREFIX_PATH="${PYTHON_PATH%/?(s)bin/*}" PYENV_PREFIX_PATH="${PYENV_PREFIX_PATH:-/}" else echo "pyenv: system version not found in PATH" >&2 diff --git a/test/prefix.bats b/test/prefix.bats index 6f63d1f7..88def509 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -24,6 +24,15 @@ load test_helper assert_success "$PYENV_TEST_DIR" } +#Arch has Python at sbin as well as bin +@test "prefix for sbin system" { + mkdir -p "${PYENV_TEST_DIR}/sbin" + touch "${PYENV_TEST_DIR}/sbin/python" + chmod +x "${PYENV_TEST_DIR}/sbin/python" + PYENV_VERSION="system" run pyenv-prefix + assert_success "$PYENV_TEST_DIR" +} + @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" cat >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" <