mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-16 15:33:51 -05:00
activate: invoke pyenv shell only if the arguments passed
This commit is contained in:
15
README.md
15
README.md
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
@@ -41,7 +40,11 @@ fi
|
||||
|
||||
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
|
||||
|
||||
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\"" ;;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -19,7 +19,6 @@ setup() {
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv";
|
||||
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||
EOS
|
||||
}
|
||||
@@ -37,7 +36,6 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv";
|
||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -21,8 +20,7 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
functions -q deactivate; and deactivate;
|
||||
pyenv shell --unset
|
||||
functions -q deactivate; and deactivate
|
||||
EOS
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user