Skip to content

Commit

Permalink
activate: invoke pyenv shell only if the arguments passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashita Yuu committed Jun 4, 2014
1 parent ea120da commit 8a83775
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
15 changes: 1 addition & 14 deletions README.md
Expand Up @@ -86,13 +86,7 @@ version.
Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv.
`pyenv activate` lets you to activate the virtualenv into your shell.

$ pyenv activate venv27

`pyenv activate` acts almost like following commands.
The activate'd virtualenv will be persisted as _shell_ version.

$ pyenv shell venv27
$ source "$(pyenv prefix venv27)/bin/activate"
$ pyenv activate

### Deactivate virtualenv

Expand All @@ -105,13 +99,6 @@ This is prepared for similality between other `pyenv` commands like `shell` and

$ pyenv activate --unset

`pyenv deactivate` acts almost like following commands.
You can also use virtualenv's `deactivate` in place of `pyenv deactivate`,
but be careful with the _shell_ version because it will be persisted even if `deactivate` has invoked.

$ deactivate
$ pyenv shell --unset

### Special environment variables

You can set certain environment variables to control the pyenv-virtualenv.
Expand Down
9 changes: 6 additions & 3 deletions bin/pyenv-sh-activate
Expand Up @@ -26,9 +26,8 @@ if [ "$1" = "--unset" ]; then
fi

versions=("$@")
shell="$(basename "${PYENV_SHELL:-$SHELL}")"

if [ -z "$versions" ]; then
no_shell=1
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name))
IFS="$OLDIFS"
Expand All @@ -41,7 +40,11 @@ fi

pyenv-virtualenv-prefix "${versions}" 1>/dev/null

echo "pyenv shell \"${versions}\";"
if [ -z "$no_shell" ]; then
echo "pyenv shell \"${versions}\";"
fi

shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
Expand Down
5 changes: 2 additions & 3 deletions bin/pyenv-sh-deactivate
Expand Up @@ -11,7 +11,6 @@ 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
echo "pyenv shell --unset"
2 changes: 0 additions & 2 deletions test/activate.bats
Expand Up @@ -19,7 +19,6 @@ setup() {

assert_success
assert_output <<EOS
pyenv shell "venv";
source "${PYENV_ROOT}/versions/venv/bin/activate"
EOS
}
Expand All @@ -37,7 +36,6 @@ EOS

assert_success
assert_output <<EOS
pyenv shell "venv";
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
EOS
}
Expand Down
6 changes: 2 additions & 4 deletions test/deactivate.bats
Expand Up @@ -11,8 +11,7 @@ setup() {

assert_success
assert_output <<EOS
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
pyenv shell --unset
declare -f deactivate 1>/dev/null 2>&1 && deactivate
EOS
}

Expand All @@ -21,8 +20,7 @@ EOS

assert_success
assert_output <<EOS
functions -q deactivate; and deactivate;
pyenv shell --unset
functions -q deactivate; and deactivate
EOS
}

Expand Down

0 comments on commit 8a83775

Please sign in to comment.