mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-09 20:13:54 -05:00
Merge branch 'activate' (fixes #9)
This commit is contained in:
17
README.md
17
README.md
@@ -78,6 +78,23 @@ version.
|
|||||||
venv33 (created from /home/yyuu/.pyenv/versions/3.3.3)
|
venv33 (created from /home/yyuu/.pyenv/versions/3.3.3)
|
||||||
|
|
||||||
|
|
||||||
|
### Activate 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 venv27
|
||||||
|
|
||||||
|
`pyenv activate` acts almost like following commands.
|
||||||
|
|
||||||
|
$ pyenv shell venv27
|
||||||
|
$ source "$(pyenv prefix venv27)/bin/activate"
|
||||||
|
|
||||||
|
You can deactivate the activate'd virtualenv by `pyenv deactivate`.
|
||||||
|
|
||||||
|
$ pyenv deactivate
|
||||||
|
|
||||||
|
|
||||||
### 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.
|
||||||
|
|||||||
48
bin/pyenv-sh-activate
Executable file
48
bin/pyenv-sh-activate
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Summary: Activate virtual environment
|
||||||
|
#
|
||||||
|
# Usage: pyenv activate <virtualenv>
|
||||||
|
# pyenv activate --unset
|
||||||
|
#
|
||||||
|
# Activate a Python virtualenv environment in current shell.
|
||||||
|
# This acts almost as same as `pyenv shell`, but this invokes the `activate`
|
||||||
|
# script in your shell.
|
||||||
|
#
|
||||||
|
# <virtualenv> should be a string matching a Python version known to pyenv.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
# Provide pyenv completions
|
||||||
|
if [ "$1" = "--complete" ]; then
|
||||||
|
echo --unset
|
||||||
|
exec pyenv-virtualenvs --bare
|
||||||
|
fi
|
||||||
|
|
||||||
|
versions=("$@")
|
||||||
|
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||||
|
|
||||||
|
if [ -z "$versions" ]; then
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
IFS=: versions=($(pyenv-version-name))
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "--unset" ]; then
|
||||||
|
echo "pyenv deactivate"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${#versions[@]}" -gt 1 ]; then
|
||||||
|
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
|
||||||
|
|
||||||
|
echo "pyenv shell \"${versions}\""
|
||||||
|
case "$shell" in
|
||||||
|
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
|
||||||
|
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
|
||||||
|
esac
|
||||||
17
bin/pyenv-sh-deactivate
Executable file
17
bin/pyenv-sh-deactivate
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Summary: Deactivate virtual environment
|
||||||
|
#
|
||||||
|
# Usage: pyenv deactivate
|
||||||
|
#
|
||||||
|
# Deactivate a Python virtual environment.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
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";;
|
||||||
|
esac
|
||||||
|
echo "pyenv shell --unset"
|
||||||
@@ -230,7 +230,7 @@ for option in "${OPTIONS[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
|
if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
|
||||||
echo "pyenv: no virtualenv name given." 1>&2
|
echo "pyenv-virtualenv: no virtualenv name given." 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
|
elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
|
||||||
# If only one argument given, use current version as source version
|
# If only one argument given, use current version as source version
|
||||||
@@ -312,7 +312,7 @@ done
|
|||||||
# the --force option was specified.
|
# the --force option was specified.
|
||||||
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
|
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
|
||||||
if [ -z "$FORCE" ]; then
|
if [ -z "$FORCE" ]; then
|
||||||
echo "pyenv: ${VIRTUALENV_PATH} already exists" 1>&2
|
echo "pyenv-virtualenv: ${VIRTUALENV_PATH} already exists" 1>&2
|
||||||
read -p "continue with installation? (y/N) "
|
read -p "continue with installation? (y/N) "
|
||||||
|
|
||||||
case "$REPLY" in
|
case "$REPLY" in
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ for version in "${versions[@]}"; do
|
|||||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
|
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "pyenv: version \`${version}' is not a virtualenv" 1>&2
|
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user