From 5f87786adf9e9527072f90ee23c9173eac985bf4 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Mon, 23 Nov 2015 12:28:10 +0000 Subject: [PATCH 1/3] Remove `PYENV_DEACTIVATE` (fixes #121) This means that pyenv-virtualenv will not allow manual deactivation of virtualenv if pyenv-virtualenv-init is enabled. This must be acceptable since the activation of virtualenv is just setting of environment variables in current implementation. --- bin/pyenv-sh-activate | 30 +++++++++--------------------- bin/pyenv-sh-deactivate | 21 ++++++++------------- bin/pyenv-virtualenv | 10 +++++----- test/activate.bats | 11 ----------- test/conda-activate.bats | 6 ------ test/conda-deactivate.bats | 4 ---- test/deactivate.bats | 23 +++++++++++------------ test/version.bats | 2 -- 8 files changed, 33 insertions(+), 74 deletions(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index e2e9b78..ba5d5c8 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -14,6 +14,10 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x +if [ -z "${PYENV_ROOT}" ]; then + PYENV_ROOT="$(pyenv-root)" +fi + resolve_link() { $(type -p greadlink readlink | head -1) "$1" } @@ -66,7 +70,7 @@ fi venv="${versions}" # exit as success if some virtualenv outside from pyenv is already activated -if [ -n "${VIRTUAL_ENV}" ]; then +if [ -n "${VIRTUAL_ENV}" ] && [[ "${VIRTUAL_ENV}" == "${VIRTUAL_ENV#${PYENV_ROOT}/versions/}" ]]; then if [ -z "${FORCE}" ]; then if [ -z "${QUIET}" ]; then echo "pyenv-virtualenv: virtualenv \`${VIRTUAL_ENV}' is already activated" 1>&2 @@ -77,7 +81,7 @@ if [ -n "${VIRTUAL_ENV}" ]; then fi if ! pyenv-virtualenv-prefix "${venv}" 1>/dev/null 2>&1; then - if [ -z "$QUIET" ]; then + if [ -z "${QUIET}" ]; then echo "pyenv-virtualenv: version \`${venv}' is not a virtualenv" 1>&2 fi echo "false" @@ -89,7 +93,7 @@ fi for version in "${versions[@]}"; do if [[ "${version}" != "${venv}" ]]; then if pyenv-virtualenv-prefix "${version}" 1>/dev/null 2>&1; then - if [ -z "$QUIET" ]; then + if [ -z "${QUIET}" ]; then echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2 fi echo "false" @@ -116,16 +120,6 @@ if [[ "${VIRTUAL_ENV}" == "${prefix}" ]]; then fi fi -if [[ "${PYENV_DEACTIVATE}" == "${prefix}" ]]; then - if [ -z "${FORCE}" ]; then - if [ -z "${QUIET}" ]; then - echo "pyenv-virtualenv: \`${venv}' is marked deactivated. use \`pyenv activate --force ${venv}' to activate forcibly." 1>&2 - fi - echo "false" - exit 1 - fi -fi - # Display setup instruction, if pyenv-virtualenv has not been initialized. # if 'pyenv virtualenv-init -' is not found in "$profile" if [ -z "$PYENV_VIRTUALENV_INIT" ]; then @@ -161,16 +155,10 @@ fi # virtualenv/pyvenv case "${shell}" in fish ) - cat <&2 + if [ -z "${FORCE}" ]; then + if [ -z "${QUIET}" ]; then + echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2 + fi + echo "false" + exit 1 fi - echo "false" - exit 1 fi shell="$(basename "${PYENV_SHELL:-$SHELL}")" @@ -72,20 +74,13 @@ fi # virtualenv/pyvenv case "${shell}" in fish ) - cat < Date: Mon, 23 Nov 2015 13:34:46 +0000 Subject: [PATCH 2/3] Suppress message about `virtualenv-init` if `-quiet` given (fixes #122) --- bin/pyenv-sh-activate | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index ba5d5c8..007fdbc 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -123,7 +123,9 @@ fi # Display setup instruction, if pyenv-virtualenv has not been initialized. # if 'pyenv virtualenv-init -' is not found in "$profile" if [ -z "$PYENV_VIRTUALENV_INIT" ]; then - pyenv-virtualenv-init >&2 || true + if [ -z "${QUIET}" ]; then + pyenv-virtualenv-init >&2 || true + fi fi pyenv-sh-deactivate --quiet ${VERBOSE+--verbose} || true From 0bbb12a3bf1e65b29837899f32ebb27ef619e17c Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Tue, 24 Nov 2015 00:04:18 +0000 Subject: [PATCH 3/3] Use glob to check if the virtualenv is inside pyenv's prefix or not --- bin/pyenv-sh-activate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 007fdbc..87d0e41 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -70,7 +70,7 @@ fi venv="${versions}" # exit as success if some virtualenv outside from pyenv is already activated -if [ -n "${VIRTUAL_ENV}" ] && [[ "${VIRTUAL_ENV}" == "${VIRTUAL_ENV#${PYENV_ROOT}/versions/}" ]]; then +if [ -n "${VIRTUAL_ENV}" ] && [[ "${VIRTUAL_ENV}" != "${PYENV_ROOT}/versions/"* ]]; then if [ -z "${FORCE}" ]; then if [ -z "${QUIET}" ]; then echo "pyenv-virtualenv: virtualenv \`${VIRTUAL_ENV}' is already activated" 1>&2