mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Compare commits
18 Commits
v1.2.1
...
e83e7496fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e83e7496fa | ||
|
|
6c523f4ce3 | ||
|
|
119c4db68c | ||
|
|
83fae32522 | ||
|
|
96d066e44c | ||
|
|
9f3afd0cfb | ||
|
|
0f83c33a3b | ||
|
|
2b2b87a25a | ||
|
|
38a6561f96 | ||
|
|
c85c1c9ed5 | ||
|
|
cd6a51ad68 | ||
|
|
85d8c5aabf | ||
|
|
fca12418ca | ||
|
|
13bc1877ef | ||
|
|
a724aaa149 | ||
|
|
f4162706d8 | ||
|
|
77a7644ff7 | ||
|
|
826f3fbe6f |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: ['https://www.bountysource.com/teams/pyenv-virtualenv/issues'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
|
||||
4
.github/ISSUE_TEMPLATE.md
vendored
4
.github/ISSUE_TEMPLATE.md
vendored
@@ -22,7 +22,11 @@ Make sure you have checked all steps below.
|
||||
* If the problem happens in a Pyenv invocation, you can turn on debug logging by setting `PYENV_DEBUG=1`, e.g. `env PYENV_DEBUG=1 pyenv install -v 3.6.4`
|
||||
* If the problem happens outside of a Pyenv invocation, get the debug log like this:
|
||||
```
|
||||
# for Bash
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
# for Zsh
|
||||
export PS4='+(%x:%I): %N(%i): '
|
||||
|
||||
set -x
|
||||
<reproduce the problem>
|
||||
set +x
|
||||
|
||||
@@ -34,6 +34,12 @@ From inside that directory you can:
|
||||
$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
|
||||
```
|
||||
|
||||
For the Fish shell:
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/pyenv/pyenv-virtualenv.git (pyenv root)/plugins/pyenv-virtualenv
|
||||
```
|
||||
|
||||
2. (OPTIONAL) **Add `pyenv virtualenv-init` to your shell** to enable auto-activation of virtualenvs. This is entirely optional but pretty useful. See "Activate virtualenv" below.
|
||||
|
||||
```sh
|
||||
@@ -237,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
|
||||
|
||||
|
||||
@@ -25,6 +25,27 @@ resolve_link() {
|
||||
unset FORCE
|
||||
unset QUIET
|
||||
|
||||
# Define `before_activate` and `after_activate` functions that allow
|
||||
# plugin hooks to register a string of code for execution before or
|
||||
# after activating a virtualenv.
|
||||
declare -a before_hooks after_hooks
|
||||
|
||||
before_activate() {
|
||||
local hook="$1"
|
||||
before_hooks["${#before_hooks[@]}"]="$hook"
|
||||
}
|
||||
|
||||
after_activate() {
|
||||
local hook="$1"
|
||||
after_hooks["${#after_hooks[@]}"]="$hook"
|
||||
}
|
||||
|
||||
# Load plugin hooks.
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks activate`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do source "$script"; done
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"--complete" )
|
||||
@@ -137,6 +158,9 @@ fi
|
||||
|
||||
pyenv-sh-deactivate --force --quiet || true
|
||||
|
||||
# Execute `before_activate` hooks.
|
||||
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
if [ -n "$PYENV_VIRTUALENV_VERBOSE_ACTIVATE" ]; then
|
||||
echo "pyenv-virtualenv: activate ${venv}" 1>&2
|
||||
fi
|
||||
@@ -221,16 +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 "${QUIET}" ]; then
|
||||
echo "pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior." 1>&2
|
||||
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
|
||||
@@ -261,3 +300,6 @@ if [ -d "${prefix}/conda-meta" ] ||
|
||||
esac
|
||||
shopt -u nullglob
|
||||
fi
|
||||
|
||||
# Execute `after_activate` hooks.
|
||||
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
@@ -16,6 +16,27 @@ fi
|
||||
unset FORCE
|
||||
unset QUIET
|
||||
|
||||
# Define `before_deactivate` and `after_deactivate` functions that allow
|
||||
# plugin hooks to register a string of code for execution before or
|
||||
# after deactivating a virtualenv.
|
||||
declare -a before_hooks after_hooks
|
||||
|
||||
before_deactivate() {
|
||||
local hook="$1"
|
||||
before_hooks["${#before_hooks[@]}"]="$hook"
|
||||
}
|
||||
|
||||
after_deactivate() {
|
||||
local hook="$1"
|
||||
after_hooks["${#after_hooks[@]}"]="$hook"
|
||||
}
|
||||
|
||||
# Load plugin hooks.
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks deactivate`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do source "$script"; done
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-f" | "--force" )
|
||||
@@ -54,6 +75,9 @@ else
|
||||
venv="${prefix##*/}"
|
||||
fi
|
||||
|
||||
# Execute `before_deactivate` hooks.
|
||||
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
if [ -n "$PYENV_VIRTUALENV_VERBOSE_ACTIVATE" ]; then
|
||||
echo "pyenv-virtualenv: deactivate ${venv}" 1>&2
|
||||
fi
|
||||
@@ -163,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
|
||||
@@ -191,3 +223,6 @@ fi;
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
# Execute `after_deactivate` hooks.
|
||||
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# -u/--upgrade Imply --force
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="1.1.5"
|
||||
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"
|
||||
}
|
||||
@@ -336,10 +342,20 @@ fi
|
||||
# Set VERSION_NAME as default version in this script
|
||||
export PYENV_VERSION="${VERSION_NAME}"
|
||||
|
||||
not_installed_message() {
|
||||
local is_available=$(python-build --definitions | grep -F -x "$1")
|
||||
echo "pyenv-virtualenv: \`${1}' is not installed in pyenv." 1>&2
|
||||
if [[ $is_available ]]; then
|
||||
echo "Run \`pyenv install ${1}' to install it." 1>&2
|
||||
else
|
||||
echo "It does not look like a valid Python version. See \`pyenv install --list' for available versions." 1>&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Source version must exist before creating virtualenv.
|
||||
PREFIX="$(pyenv-prefix 2>/dev/null || true)"
|
||||
if [ ! -d "${PREFIX}" ]; then
|
||||
echo "pyenv-virtualenv: \`${PYENV_VERSION}' is not installed in pyenv." 1>&2
|
||||
not_installed_message "${PYENV_VERSION}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -441,7 +457,8 @@ else
|
||||
if [ -x "${python}" ]; then
|
||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${python}"
|
||||
else
|
||||
echo "pyenv-virtualenv: \`${VIRTUALENV_PYTHON##*/}' is not installed in pyenv." 1>&2
|
||||
# echo "pyenv-virtualenv: \`${VIRTUALENV_PYTHON##*/}' is not installed in pyenv." 1>&2
|
||||
not_installed_message "${VIRTUALENV_PYTHON##*/}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@@ -589,6 +606,15 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
(
|
||||
shopt -s nullglob
|
||||
for extra_binary in "$PREFIX"/bin/python*-config; do
|
||||
extra_binary_linkname="$VIRTUALENV_PATH/bin/$(basename $extra_binary)"
|
||||
[[ -e "$extra_binary_linkname" ]] || \
|
||||
ln -s "$extra_binary" "$extra_binary_linkname"
|
||||
done
|
||||
)
|
||||
|
||||
## Create symlink in the `versions` directory for backward compatibility
|
||||
if [ -d "${VIRTUALENV_PATH}" ] && [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
|
||||
ln -fs "${VIRTUALENV_PATH}" "${COMPAT_VIRTUALENV_PATH}"
|
||||
|
||||
@@ -15,7 +15,9 @@ 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"
|
||||
}
|
||||
|
||||
@test "activate virtualenv from current version" {
|
||||
@@ -33,7 +35,6 @@ setup() {
|
||||
deactivated
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv) \${PS1:-}";
|
||||
EOS
|
||||
@@ -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
|
||||
|
||||
@@ -86,7 +112,6 @@ deactivated
|
||||
pyenv-virtualenv: activate venv
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv) \${PS1:-}";
|
||||
EOS
|
||||
@@ -114,7 +139,6 @@ export PYENV_VERSION="venv";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv) \${PS1:-}";
|
||||
EOS
|
||||
@@ -140,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
|
||||
@@ -166,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
|
||||
@@ -191,7 +237,6 @@ export PYENV_VERSION="venv27";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv27) \${PS1:-}";
|
||||
EOS
|
||||
@@ -217,7 +262,6 @@ export PYENV_VERSION="venv27";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv27) \${PS1:-}";
|
||||
EOS
|
||||
@@ -243,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
|
||||
@@ -267,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
|
||||
@@ -390,7 +456,6 @@ export PYENV_VERSION="venv27:2.7.10";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv27) \${PS1:-}";
|
||||
EOS
|
||||
|
||||
@@ -16,7 +16,13 @@ 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"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
unstub pyenv-hooks
|
||||
}
|
||||
|
||||
@test "activate conda root from current version" {
|
||||
@@ -36,7 +42,6 @@ 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";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(anaconda-2.3.0) \${PS1:-}";
|
||||
export CONDA_PREFIX="${TMP}/pyenv/versions/anaconda-2.3.0";
|
||||
@@ -49,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
|
||||
|
||||
@@ -66,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
|
||||
@@ -95,7 +140,6 @@ export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1";
|
||||
export CONDA_DEFAULT_ENV="root";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(miniconda-3.9.1) \${PS1:-}";
|
||||
export CONDA_PREFIX="${TMP}/pyenv/versions/miniconda-3.9.1";
|
||||
@@ -125,7 +169,6 @@ deactivated
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo";
|
||||
export CONDA_DEFAULT_ENV="foo";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(anaconda-2.3.0/envs/foo) \${PS1:-}";
|
||||
export CONDA_PREFIX="${TMP}/pyenv/versions/anaconda-2.3.0/envs/foo";
|
||||
@@ -158,7 +201,6 @@ export PYENV_ACTIVATE_SHELL=1;
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1/envs/bar";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1/envs/bar";
|
||||
export CONDA_DEFAULT_ENV="bar";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(miniconda-3.9.1/envs/bar) \${PS1:-}";
|
||||
export CONDA_PREFIX="${TMP}/pyenv/versions/miniconda-3.9.1/envs/bar";
|
||||
|
||||
@@ -16,6 +16,11 @@ setup() {
|
||||
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
stub pyenv-hooks "deactivate : echo"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
unstub pyenv-hooks
|
||||
}
|
||||
|
||||
@test "deactivate conda root" {
|
||||
@@ -77,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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bats
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@@ -16,6 +16,7 @@ setup() {
|
||||
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
stub pyenv-hooks "deactivate : echo"
|
||||
}
|
||||
|
||||
@test "deactivate virtualenv" {
|
||||
@@ -224,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;
|
||||
@@ -250,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;
|
||||
@@ -278,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;
|
||||
@@ -306,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;
|
||||
@@ -332,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" {
|
||||
@@ -40,3 +41,74 @@ OUT
|
||||
unstub pyenv-rehash
|
||||
teardown_version "3.5.1"
|
||||
}
|
||||
|
||||
@test "pyenv-sh-activate hooks" {
|
||||
cat > "${HOOK_PATH}/activate.bash" <<OUT
|
||||
before_activate 'echo "before"'
|
||||
after_activate 'echo "after"'
|
||||
OUT
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
|
||||
stub pyenv-version-name "echo venv"
|
||||
stub pyenv-virtualenv-prefix ""
|
||||
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||
stub pyenv-hooks "activate : echo '$HOOK_PATH'/activate.bash"
|
||||
stub pyenv-sh-deactivate ""
|
||||
|
||||
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
before
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
export _OLD_VIRTUAL_PS1="\${PS1:-}";
|
||||
export PS1="(venv) \${PS1:-}";
|
||||
after
|
||||
EOS
|
||||
|
||||
unstub pyenv-version-name
|
||||
unstub pyenv-virtualenv-prefix
|
||||
unstub pyenv-prefix
|
||||
unstub pyenv-hooks
|
||||
unstub pyenv-sh-deactivate
|
||||
}
|
||||
|
||||
@test "deactivate virtualenv" {
|
||||
cat > "${HOOK_PATH}/deactivate.bash" <<OUT
|
||||
before_deactivate 'echo "before"'
|
||||
after_deactivate 'echo "after"'
|
||||
OUT
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
|
||||
export PYENV_ACTIVATE_SHELL=
|
||||
stub pyenv-hooks "deactivate : echo '$HOOK_PATH'/deactivate.bash"
|
||||
|
||||
PYENV_SHELL="bash" run pyenv-sh-deactivate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
before
|
||||
unset PYENV_VIRTUAL_ENV;
|
||||
unset VIRTUAL_ENV;
|
||||
if [ -n "\${_OLD_VIRTUAL_PATH:-}" ]; then
|
||||
export PATH="\${_OLD_VIRTUAL_PATH}";
|
||||
unset _OLD_VIRTUAL_PATH;
|
||||
fi;
|
||||
if [ -n "\${_OLD_VIRTUAL_PYTHONHOME:-}" ]; then
|
||||
export PYTHONHOME="\${_OLD_VIRTUAL_PYTHONHOME}";
|
||||
unset _OLD_VIRTUAL_PYTHONHOME;
|
||||
fi;
|
||||
if [ -n "\${_OLD_VIRTUAL_PS1:-}" ]; then
|
||||
export PS1="\${_OLD_VIRTUAL_PS1}";
|
||||
unset _OLD_VIRTUAL_PS1;
|
||||
fi;
|
||||
if declare -f deactivate 1>/dev/null 2>&1; then
|
||||
unset -f deactivate;
|
||||
fi;
|
||||
after
|
||||
EOS
|
||||
|
||||
unstub pyenv-hooks
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ setup() {
|
||||
stub pyenv-rehash " : true"
|
||||
stub pyenv-version-name "echo \${PYENV_VERSION}"
|
||||
stub curl true
|
||||
stub python-build "echo python2.7"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
@@ -22,6 +23,7 @@ teardown() {
|
||||
unstub pyenv-prefix
|
||||
unstub pyenv-hooks
|
||||
unstub pyenv-rehash
|
||||
unstub python-build
|
||||
teardown_version "2.7.8"
|
||||
rm -fr "$TMP"/*
|
||||
}
|
||||
@@ -96,6 +98,7 @@ OUT
|
||||
|
||||
assert_output <<OUT
|
||||
pyenv-virtualenv: \`python2.7' is not installed in pyenv.
|
||||
Run \`pyenv install python2.7' to install it.
|
||||
OUT
|
||||
assert_failure
|
||||
|
||||
@@ -106,3 +109,13 @@ OUT
|
||||
remove_executable "2.7.8" "python2.7"
|
||||
remove_executable "2.7.9" "python2.7"
|
||||
}
|
||||
|
||||
@test "invalid python name" {
|
||||
run pyenv-virtualenv --verbose --python=99.99.99 venv
|
||||
|
||||
assert_output <<OUT
|
||||
pyenv-virtualenv: \`99.99.99' is not installed in pyenv.
|
||||
It does not look like a valid Python version. See \`pyenv install --list' for available versions.
|
||||
OUT
|
||||
assert_failure
|
||||
}
|
||||
@@ -29,10 +29,13 @@ unstub_pyenv() {
|
||||
stub pyenv-exec "python2.7 -m venv --help : false"
|
||||
stub pyenv-exec "python2 -m venv --help : false"
|
||||
stub pyenv-exec "python -m venv --help : false"
|
||||
stub pyenv-exec "virtualenv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
|
||||
stub pyenv-exec "virtualenv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"; mkdir -p \"\$2/bin\""
|
||||
stub pyenv-exec "python -s -m ensurepip : false"
|
||||
stub pyenv-exec "python -s */get-pip.py : true"
|
||||
stub curl true
|
||||
create_executable "${PYENV_VERSION}" "python-config"
|
||||
create_executable "${PYENV_VERSION}" "python2-config"
|
||||
create_executable "${PYENV_VERSION}" "python2.7-config"
|
||||
|
||||
run pyenv-virtualenv "2.7.11" "venv"
|
||||
|
||||
@@ -41,8 +44,10 @@ PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
|
||||
Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
|
||||
rehashed
|
||||
OUT
|
||||
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
|
||||
assert_success
|
||||
for x in pydoc python-config python2-config python2.7-config; do
|
||||
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/$x" ]
|
||||
done
|
||||
|
||||
unstub_pyenv
|
||||
unstub pyenv-virtualenv-prefix
|
||||
|
||||
Reference in New Issue
Block a user