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.
|
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` lets you to activate the virtualenv into your shell.
|
||||||
|
|
||||||
$ pyenv activate venv27
|
$ pyenv activate
|
||||||
|
|
||||||
`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"
|
|
||||||
|
|
||||||
### Deactivate virtualenv
|
### Deactivate virtualenv
|
||||||
|
|
||||||
@@ -105,13 +99,6 @@ This is prepared for similality between other `pyenv` commands like `shell` and
|
|||||||
|
|
||||||
$ pyenv activate --unset
|
$ 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
|
### Special environment variables
|
||||||
|
|
||||||
You can set certain environment variables to control the pyenv-virtualenv.
|
You can set certain environment variables to control the pyenv-virtualenv.
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ if [ "$1" = "--unset" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
versions=("$@")
|
versions=("$@")
|
||||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
|
||||||
|
|
||||||
if [ -z "$versions" ]; then
|
if [ -z "$versions" ]; then
|
||||||
|
no_shell=1
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: versions=($(pyenv-version-name))
|
IFS=: versions=($(pyenv-version-name))
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
@@ -41,7 +40,11 @@ fi
|
|||||||
|
|
||||||
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
|
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
|
case "$shell" in
|
||||||
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
|
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
|
||||||
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
|
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ set -e
|
|||||||
|
|
||||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish ) echo "functions -q deactivate; and deactivate;";;
|
fish ) echo "functions -q deactivate; and deactivate";;
|
||||||
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
|
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
|
||||||
esac
|
esac
|
||||||
echo "pyenv shell --unset"
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ setup() {
|
|||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
assert_output <<EOS
|
||||||
pyenv shell "venv";
|
|
||||||
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,6 @@ EOS
|
|||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
assert_output <<EOS
|
||||||
pyenv shell "venv";
|
|
||||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ setup() {
|
|||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
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
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,8 +20,7 @@ EOS
|
|||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
assert_output <<EOS
|
||||||
functions -q deactivate; and deactivate;
|
functions -q deactivate; and deactivate
|
||||||
pyenv shell --unset
|
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user