Browse Source

Merge branch 'issue26'

pull/27/head
Yamashita Yuu 10 years ago
parent
commit
56a3225d6c
5 changed files with 111 additions and 4 deletions
  1. +6
    -0
      bin/pyenv-sh-activate
  2. +8
    -2
      bin/pyenv-sh-deactivate
  3. +3
    -0
      bin/pyenv-virtualenv-init
  4. +64
    -0
      test/activate.bats
  5. +30
    -2
      test/deactivate.bats

+ 6
- 0
bin/pyenv-sh-activate View File

@ -33,6 +33,12 @@ if [ -z "$versions" ]; then
IFS="$OLDIFS"
fi
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
# Backward compatibility issue
# https://github.com/yyuu/pyenv-virtualenv/issues/26
no_shell=
fi
if [ "${#versions[@]}" -gt 1 ]; then
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
exit 1

+ 8
- 2
bin/pyenv-sh-deactivate View File

@ -11,6 +11,12 @@ set -e
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
fish ) echo "functions -q deactivate; and deactivate";;
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
fish ) echo "functions -q deactivate; and deactivate;";;
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
esac
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
# Backward compatibility issue
# https://github.com/yyuu/pyenv-virtualenv/issues/26
echo "pyenv shell --unset"
fi

+ 3
- 0
bin/pyenv-virtualenv-init View File

@ -65,6 +65,7 @@ fi
case "$shell" in
bash )
cat <<EOS
export PYENV_VIRTUALENV_INIT=1
_pyenv_virtualenv_hook() {
if [[ "\$(pyenv version-name)" == "system" ]]; then
pyenv deactivate || true;
@ -80,6 +81,7 @@ EOS
;;
fish )
cat <<EOS
setenv PYENV_VIRTUALENV_INIT=1;
function _pyenv_virtualenv_hook --on-event fish_prompt;
if [ (pyenv version-name) = "system" ]
eval (pyenv sh-deactivate); or true
@ -92,6 +94,7 @@ EOS
;;
zsh )
cat <<EOS
export PYENV_VIRTUALENV_INIT=1
_pyenv_virtualenv_hook() {
if [[ "\$(pyenv version-name)" == "system" ]]; then
pyenv deactivate || true

+ 64
- 0
test/activate.bats View File

@ -8,6 +8,8 @@ setup() {
}
@test "activate virtualenv from current version" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
@ -24,7 +26,29 @@ source "${PYENV_ROOT}/versions/venv/bin/activate"
EOS
}
@test "activate virtualenv from current version (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv";
source "${PYENV_ROOT}/versions/venv/bin/activate"
EOS
}
@test "activate virtualenv from current version (fish)" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
@ -41,7 +65,47 @@ EOS
EOS
}
@test "activate virtualenv from current version (fish) (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv";
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
EOS
}
@test "activate virtualenv from command-line argument" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv27";
source "${PYENV_ROOT}/versions/venv27/bin/activate"
EOS
}
@test "activate virtualenv from command-line argument (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""

+ 30
- 2
test/deactivate.bats View File

@ -7,20 +7,48 @@ setup() {
}
@test "deactivate virtualenv" {
export PYENV_VIRTUALENV_INIT=1
PYENV_SHELL="bash" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
EOS
}
@test "deactivate virtualenv (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
PYENV_SHELL="bash" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
declare -f deactivate 1>/dev/null 2>&1 && deactivate
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
pyenv shell --unset
EOS
}
@test "deactivate virtualenv (fish)" {
export PYENV_VIRTUALENV_INIT=1
PYENV_SHELL="fish" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
functions -q deactivate; and deactivate;
EOS
}
@test "deactivate virtualenv (fish) (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
PYENV_SHELL="fish" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
functions -q deactivate; and deactivate
functions -q deactivate; and deactivate;
pyenv shell --unset
EOS
}

Loading…
Cancel
Save