diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index be7e453..6f8e90c 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -81,11 +81,21 @@ if [ -n "${VIRTUAL_ENV}" ] && [[ "${VIRTUAL_ENV}" != "${PYENV_ROOT}/versions/"* fi if ! pyenv-virtualenv-prefix "${venv}" 1>/dev/null 2>&1; then - if [ -z "${QUIET}" ]; then - echo "pyenv-virtualenv: version \`${venv}' is not a virtualenv" 1>&2 + # fallback to virtualenv of current version + OLDIFS="$IFS" + IFS=: current_versions=($(pyenv-version-name)) + IFS="$OLDIFS" + new_venv="${current_versions%/envs/*}/envs/${venv}" + if pyenv-virtualenv-prefix "${new_venv}" 1>/dev/null 2>&1; then + venv="${new_venv}" + versions[0]="${new_venv}" + else + if [ -z "${QUIET}" ]; then + echo "pyenv-virtualenv: version \`${venv}' is not a virtualenv" 1>&2 + fi + echo "false" + exit 1 fi - echo "false" - exit 1 fi # exit as error if there are multiple virtualenvs diff --git a/test/activate.bats b/test/activate.bats index 4b48130..e249178 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -27,11 +27,6 @@ setup() { PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate - unstub pyenv-version-name - unstub pyenv-virtualenv-prefix - unstub pyenv-prefix - stub pyenv-sh-deactivate - assert_success assert_output <