Skip to content

Commit

Permalink
Don't activate if a 3rd-party virtualenv is active over ours
Browse files Browse the repository at this point in the history
  • Loading branch information
native-api committed Apr 3, 2024
1 parent 45a28ac commit ac28398
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/pyenv-sh-activate
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ fi
venv="${versions}"

if [ -n "${VIRTUAL_ENV}" ]; then
# exit as success if some virtualenv is already activated outside from pyenv-virtualenv
if [ -z "${PYENV_VIRTUAL_ENV}" ]; then
# exit as success if a non-pyenv virtualenv is active
if [[ -z $PYENV_VIRTUAL_ENV || $PYENV_VIRTUAL_ENV != "$VIRTUAL_ENV" ]]; then
if [ -z "${FORCE}" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: virtualenv \`${VIRTUAL_ENV}' is already activated" 1>&2
Expand Down
28 changes: 28 additions & 0 deletions test/activate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,34 @@ EOS
unstub pyenv-prefix
}

@test "do nothing if a 3rd-party virtualenv is active" {
export PYENV_VIRTUALENV_INIT=1
export VIRTUAL_ENV="${TMP}/venv-3rd-party"
unset PYENV_VIRTUAL_ENV

PYENV_SHELL="bash" run pyenv-sh-activate "venv"

assert_success
assert_output <<EOS
pyenv-virtualenv: virtualenv \`${TMP}/venv-3rd-party' is already activated
true
EOS
}

@test "do nothing if a 3rd-party virtualenv is active over ours" {
export PYENV_VIRTUALENV_INIT=1
export VIRTUAL_ENV="${TMP}/venv-3rd-party"
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"

PYENV_SHELL="bash" run pyenv-sh-activate "venv"

assert_success
assert_output <<EOS
pyenv-virtualenv: virtualenv \`${TMP}/venv-3rd-party' is already activated
true
EOS
}

@test "should fail if activate is invoked as a command" {
run pyenv-activate

Expand Down

0 comments on commit ac28398

Please # to comment.