From 4df7cf2dd6d2cf6319d5f6743cacbb3db8a7f3d9 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Thu, 21 Jul 2016 02:45:27 +0000 Subject: [PATCH 1/5] Add workaround for `/bin/python` (#628) --- libexec/pyenv-prefix | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/pyenv-prefix b/libexec/pyenv-prefix index 9b73795e..ac04f6bc 100755 --- a/libexec/pyenv-prefix +++ b/libexec/pyenv-prefix @@ -32,6 +32,7 @@ OLDIFS="$IFS" if [ "$version" = "system" ]; then if PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python 2>/dev/null)"; then PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" + PYENV_PREFIX_PATH="${PYENV_PREFIX_PATH:-/}" else echo "pyenv: system version not found in PATH" >&2 exit 1 From 5c83c4abb7ea93d6d213e73129ceb18be7d7ec58 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Mon, 1 Aug 2016 00:19:04 +0000 Subject: [PATCH 2/5] Add test for `/bin/python` case --- test/prefix.bats | 9 +++++++++ test/test_helper.bash | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/prefix.bats b/test/prefix.bats index be9dbaed..1bad28dd 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -24,6 +24,15 @@ load test_helper assert_success "$PYENV_TEST_DIR" } +@test "prefix for system in /" { + mkdir -p "${PYENV_TEST_DIR}/bin" + touch "${PYENV_TEST_DIR}/bin/pyenv-which" + echo "echo /bin/python" >"${PYENV_TEST_DIR}/bin/pyenv-which" + chmod +x "${PYENV_TEST_DIR}/bin/pyenv-which" + PYENV_VERSION="system" run pyenv-prefix + assert_success "/" +} + @test "prefix for invalid system" { PATH="$(path_without python)" run pyenv-prefix system assert_failure "pyenv: system version not found in PATH" diff --git a/test/test_helper.bash b/test/test_helper.bash index e11cd8f1..94e36168 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -20,10 +20,10 @@ if [ -z "$PYENV_TEST_DIR" ]; then export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - PATH="${PYENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${PYENV_ROOT}/shims:$PATH" + PATH="${PYENV_TEST_DIR}/bin:$PATH" export PATH for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done From b8885e4fe2550f8fb71c0ecaf6c755f454ec0d93 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Tue, 2 Aug 2016 00:23:47 +0000 Subject: [PATCH 3/5] Keep using original PATH ordering in `test_helper` --- test/prefix.bats | 9 +++++---- test/test_helper.bash | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index 1bad28dd..c0f73627 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -25,12 +25,13 @@ load test_helper } @test "prefix for system in /" { - mkdir -p "${PYENV_TEST_DIR}/bin" - touch "${PYENV_TEST_DIR}/bin/pyenv-which" - echo "echo /bin/python" >"${PYENV_TEST_DIR}/bin/pyenv-which" - chmod +x "${PYENV_TEST_DIR}/bin/pyenv-which" + mkdir -p "${BATS_TEST_DIRNAME}/libexec" + touch "${BATS_TEST_DIRNAME}/libexec/pyenv-which" + echo "echo /bin/python" >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" + chmod +x "${BATS_TEST_DIRNAME}/libexec/pyenv-which" PYENV_VERSION="system" run pyenv-prefix assert_success "/" + rm -f "${BATS_TEST_DIRNAME}/libexec/pyenv-which" } @test "prefix for invalid system" { diff --git a/test/test_helper.bash b/test/test_helper.bash index 94e36168..e11cd8f1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -20,10 +20,10 @@ if [ -z "$PYENV_TEST_DIR" ]; then export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin + PATH="${PYENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${PYENV_ROOT}/shims:$PATH" - PATH="${PYENV_TEST_DIR}/bin:$PATH" export PATH for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done From 1b35cfaa2cc0e9ad73c69bd40e27201b40230e0f Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Wed, 3 Aug 2016 01:34:42 +0000 Subject: [PATCH 4/5] 1) Remove useless `touch` 2) Add explicit shebang line to executable for testing --- test/prefix.bats | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index c0f73627..94f7739b 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -26,8 +26,9 @@ load test_helper @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" - touch "${BATS_TEST_DIRNAME}/libexec/pyenv-which" - echo "echo /bin/python" >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" + { echo "#!/bin/sh" + echo "echo /bin/python" + } >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" chmod +x "${BATS_TEST_DIRNAME}/libexec/pyenv-which" PYENV_VERSION="system" run pyenv-prefix assert_success "/" From 93ece2ac16fa3ae4a604775c6cf4754d89ac0971 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Wed, 3 Aug 2016 06:31:27 +0000 Subject: [PATCH 5/5] Rewrite with using here document syntax --- test/prefix.bats | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index 94f7739b..6f63d1f7 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -26,9 +26,10 @@ load test_helper @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" - { echo "#!/bin/sh" - echo "echo /bin/python" - } >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" + cat >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" <