mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-12 05:23:53 -05:00
Compare commits
9 Commits
v1.2.2
...
e83e7496fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e83e7496fa | ||
|
|
6c523f4ce3 | ||
|
|
119c4db68c | ||
|
|
83fae32522 | ||
|
|
96d066e44c | ||
|
|
9f3afd0cfb | ||
|
|
0f83c33a3b | ||
|
|
2b2b87a25a | ||
|
|
38a6561f96 |
@@ -243,6 +243,7 @@ You can set certain environment variables to control pyenv-virtualenv.
|
||||
* `PIP_VERSION`, if set and `venv` is preferred
|
||||
over `virtualenv`, install the specified version of pip.
|
||||
* `PYENV_VIRTUALENV_VERBOSE_ACTIVATE`, if set, shows some verbose outputs on activation and deactivation
|
||||
* `PYENV_VIRTUALENV_PROMPT`, if set, allows users to customize how `pyenv-virtualenv` modifies their shell prompt. The default prompt ("(venv)") is overwritten with any user-specified text. Specify the location of the virtual environment name with the string `{venv}`. For example, the default prompt string would be `({venv})`.
|
||||
|
||||
## Version History
|
||||
|
||||
|
||||
@@ -245,13 +245,31 @@ if [ -z "${PYENV_VIRTUALENV_DISABLE_PROMPT}" ]; then
|
||||
case "${shell}" in
|
||||
fish )
|
||||
if [ -z "${QUIET}" ]; then
|
||||
echo "pyenv-virtualenv: prompt changing not working for fish." 1>&2
|
||||
cat <<EOS
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(${venv}) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
fi
|
||||
;;
|
||||
* )
|
||||
if [ -z "${PYENV_VIRTUALENV_PROMPT}" ]; then
|
||||
PYENV_VIRTUALENV_PROMPT="(${venv})"
|
||||
else
|
||||
PYENV_VIRTUALENV_PROMPT="${PYENV_VIRTUALENV_PROMPT/\{venv\}/${venv}}"
|
||||
fi
|
||||
cat <<EOS
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(${venv}) \${PS1:-}";
|
||||
export PS1="${PYENV_VIRTUALENV_PROMPT} \${PS1:-}";
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -187,7 +187,15 @@ esac
|
||||
|
||||
case "${shell}" in
|
||||
fish )
|
||||
:
|
||||
cat <<EOS
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# -u/--upgrade Imply --force
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="1.2.1"
|
||||
PYENV_VIRTUALENV_VERSION="1.2.2"
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
@@ -54,6 +54,12 @@ parse_options() {
|
||||
done
|
||||
}
|
||||
|
||||
colorize() {
|
||||
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
|
||||
else echo -n "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ setup() {
|
||||
unset PYENV_VIRTUALENV_DISABLE_PROMPT
|
||||
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset PYENV_VIRTUALENV_PROMPT
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
stub pyenv-hooks "activate : echo"
|
||||
}
|
||||
@@ -44,6 +45,31 @@ EOS
|
||||
unstub pyenv-sh-deactivate
|
||||
}
|
||||
|
||||
@test "activate virtualenv from current version with custom prompt" {
|
||||
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\""
|
||||
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
|
||||
|
||||
PYENV_SHELL="bash" PYENV_VERSION="venv" PYENV_VIRTUALENV_PROMPT='venv:{venv}' run pyenv-sh-activate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
deactivated
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="venv:venv \${PS1:-}";
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
unstub pyenv-virtualenv-prefix
|
||||
unstub pyenv-prefix
|
||||
unstub pyenv-sh-deactivate
|
||||
}
|
||||
|
||||
@test "activate virtualenv from current version (quiet)" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
|
||||
@@ -138,7 +164,18 @@ EOS
|
||||
deactivated
|
||||
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing not working for fish.
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(venv) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
@@ -164,7 +201,18 @@ set -gx PYENV_VERSION "venv";
|
||||
set -gx PYENV_ACTIVATE_SHELL 1;
|
||||
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing not working for fish.
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(venv) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
@@ -239,7 +287,18 @@ set -gx PYENV_VERSION "venv27";
|
||||
set -gx PYENV_ACTIVATE_SHELL 1;
|
||||
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing not working for fish.
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(venv27) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
|
||||
unstub pyenv-virtualenv-prefix
|
||||
@@ -263,7 +322,18 @@ set -gx PYENV_VERSION "venv27";
|
||||
set -gx PYENV_ACTIVATE_SHELL 1;
|
||||
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing not working for fish.
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(venv27) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
|
||||
unstub pyenv-virtualenv-prefix
|
||||
|
||||
@@ -16,6 +16,7 @@ setup() {
|
||||
unset PYENV_VIRTUALENV_DISABLE_PROMPT
|
||||
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset PYENV_VIRTUALENV_PROMPT
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
stub pyenv-hooks "activate : echo"
|
||||
}
|
||||
@@ -53,6 +54,35 @@ EOS
|
||||
teardown_conda "anaconda-2.3.0"
|
||||
}
|
||||
|
||||
@test "activate conda root from current version with custom prompt" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
|
||||
setup_conda "anaconda-2.3.0"
|
||||
stub pyenv-version-name "echo anaconda-2.3.0"
|
||||
stub pyenv-virtualenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
|
||||
stub pyenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
|
||||
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
|
||||
|
||||
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0" PYENV_VIRTUALENV_PROMPT='venv:{venv}' run pyenv-sh-activate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
deactivated
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
|
||||
export CONDA_DEFAULT_ENV="root";
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="venv:anaconda-2.3.0 \${PS1:-}";
|
||||
export CONDA_PREFIX="${TMP}/pyenv/versions/anaconda-2.3.0";
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
unstub pyenv-virtualenv-prefix
|
||||
unstub pyenv-prefix
|
||||
unstub pyenv-sh-deactivate
|
||||
teardown_conda "anaconda-2.3.0"
|
||||
}
|
||||
|
||||
@test "activate conda root from current version (fish)" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
|
||||
@@ -70,7 +100,18 @@ deactivated
|
||||
set -gx PYENV_VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
|
||||
set -gx VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
|
||||
set -gx CONDA_DEFAULT_ENV "root";
|
||||
pyenv-virtualenv: prompt changing not working for fish.
|
||||
functions -e _pyenv_old_prompt # remove old prompt function if exists.
|
||||
# since everything is in memory, it's safe to
|
||||
# remove it.
|
||||
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
|
||||
|
||||
# from python-venv
|
||||
function fish_prompt
|
||||
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
|
||||
# read exit status
|
||||
echo -n "(anaconda-2.3.0) " # add virtualenv to prompt
|
||||
string join -- \n \$prompt # handle multiline prompts
|
||||
end
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
|
||||
@@ -82,6 +82,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
|
||||
@@ -225,6 +225,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
@@ -251,6 +258,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
@@ -279,6 +293,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
@@ -307,6 +328,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
@@ -333,6 +361,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
|
||||
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME;
|
||||
end;
|
||||
# check if old prompt function exists
|
||||
if functions -q _pyenv_old_prompt
|
||||
# remove old prompt function if exists.
|
||||
functions -e fish_prompt
|
||||
functions -c _pyenv_old_prompt fish_prompt
|
||||
functions -e _pyenv_old_prompt
|
||||
end
|
||||
if functions -q deactivate;
|
||||
functions -e deactivate;
|
||||
end;
|
||||
|
||||
@@ -6,6 +6,7 @@ setup() {
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
export HOOK_PATH="${TMP}/i has hooks"
|
||||
mkdir -p "$HOOK_PATH"
|
||||
unset PYENV_VIRTUALENV_PROMPT
|
||||
}
|
||||
|
||||
@test "pyenv-virtualenv hooks" {
|
||||
|
||||
Reference in New Issue
Block a user