Activate a virtualenv of current version if specified version is not a virtualenv

```sh
% pyenv versions
  system
* miniconda3-3.16.0 (set by PYENV_VERSION environment variable)
  miniconda3-3.16.0/envs/venv
% pyenv activate venv
pyenv-virtualenv: deactivate miniconda3-3.16.0
pyenv-virtualenv: activate miniconda3-3.16.0/envs/venv
```
This commit is contained in:
Yamashita, Yuu
2015-11-26 23:53:00 +00:00
parent 35732c8393
commit 116e133c90
2 changed files with 80 additions and 57 deletions

View File

@@ -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