From dc12a345d8cd9e74a3709993f3c0cdfd0dda45c8 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Sun, 15 Jun 2014 18:08:10 +0900 Subject: [PATCH] Workaround for the issue with pyenv-which-ext (refs #26) --- bin/pyenv-virtualenv | 6 ++- test/hooks.bats | 12 +++--- test/pyvenv.bats | 92 ++++++++++++++++++++++--------------------- test/test_helper.bash | 10 +++++ test/version.bats | 30 ++++++++------ test/virtualenv.bats | 11 ++++-- 6 files changed, 94 insertions(+), 67 deletions(-) diff --git a/bin/pyenv-virtualenv b/bin/pyenv-virtualenv index f50eef8..feca2ad 100755 --- a/bin/pyenv-virtualenv +++ b/bin/pyenv-virtualenv @@ -124,10 +124,12 @@ usage() { } detect_venv() { - if pyenv-which "virtualenv" 1>/dev/null 2>&1; then + # Check the existence of executables as a workaround for the issue with pyenv-which-ext + # https://github.com/yyuu/pyenv-virtualenv/issues/26 + if [ -x "$(pyenv-prefix)/bin/virtualenv" ]; then HAS_VIRTUALENV=1 fi - if pyenv-which "pyvenv" 1>/dev/null 2>&1; then + if [ -x "$(pyenv-prefix)/bin/pyvenv" ]; then HAS_PYVENV=1 fi # Use pyvenv only if there is pyvenv, virtualenv is not installed, and `-p` not given diff --git a/test/hooks.bats b/test/hooks.bats index e96a2f8..5828bc6 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -13,14 +13,16 @@ setup() { before_virtualenv 'echo before: \$VIRTUALENV_PATH' after_virtualenv 'echo after: \$STATUS' OUT - stub pyenv-prefix "echo '${PYENV_ROOT}/versions/\${PYENV_VERSION}'" - stub pyenv-which "virtualenv : echo '${PYENV_ROOT}/versions/bin/virtualenv'" \ - "pyvenv : false" + stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'" + stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'" + stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'" stub pyenv-hooks "virtualenv : echo '$HOOK_PATH'/virtualenv.bash" - stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" + stub pyenv-exec "echo PYENV_VERSION=3.2.1 \"\$@\"" stub pyenv-rehash "echo rehashed" - mkdir -p "${PYENV_ROOT}/versions/3.2.1" + create_executable "3.2.1" "virtualenv" + remove_executable "3.2.1" "pyvenv" + run pyenv-virtualenv "3.2.1" venv assert_success diff --git a/test/pyvenv.bats b/test/pyvenv.bats index 5cfd043..88aa324 100644 --- a/test/pyvenv.bats +++ b/test/pyvenv.bats @@ -9,7 +9,7 @@ setup() { stub_pyenv() { export PYENV_VERSION="$1" stub pyenv-version-name "echo \${PYENV_VERSION}" - stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/\${PYENV_VERSION}'" + stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-hooks "virtualenv : echo" stub pyenv-rehash " : echo rehashed" } @@ -22,68 +22,64 @@ unstub_pyenv() { unstub pyenv-rehash } -create_executable() { - mkdir -p "${PYENV_ROOT}/versions/$1/bin" - touch "${PYENV_ROOT}/versions/$1/bin/$2" - chmod +x "${PYENV_ROOT}/versions/$1/bin/$2" -} - -remove_executable() { - rm -f "${PYENV_ROOT}/versions/$1/bin/$2" - -} - @test "use pyvenv if virtualenv is not available" { - stub_pyenv "3.4.0" - stub pyenv-which "virtualenv : false" - stub pyenv-which "pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'" + stub_pyenv "3.4.1" + stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" + stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" stub pyenv-exec "bin=\"${PYENV_ROOT}/versions/venv/bin\";mkdir -p \"\$bin\";touch \"\$bin/pip3.4\";echo PYENV_VERSION=\${PYENV_VERSION} ensurepip" stub pyenv-exec "echo 3.4" + remove_executable "3.4.1" "virtualenv" + create_executable "3.4.1" "pyvenv" + run pyenv-virtualenv venv assert_success assert_output <