Merge branch 'master' into pr

This commit is contained in:
Ivan Pozdeev
2022-10-12 21:32:12 +03:00
14 changed files with 94 additions and 78 deletions

37
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,37 @@
name: tests
on: [pull_request, push]
jobs:
tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-20.04
- macos-12
- macos-11
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
# Normally, we would use the superbly maintained...
# - uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# ... but in the repo, we want to test pyenv builds on Ubuntu
# - run: |
# sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
# libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
# xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# https://github.com/pyenv/pyenv#installation
#- env:
# PYENV_ROOT: /home/runner/work/pyenv/pyenv
# run: |
# echo $PYENV_ROOT
# echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
# macos-11 Github Actions env has an old `readlink` and lacks `greadlink` which causes Bats to break
- run: |
if [[ $RUNNER_OS == "macOS" ]] && [[ $(sw_vers -productVersion | awk -F. '{print $1}') -lt 12 ]]; then
brew install coreutils
fi
- run: git clone https://github.com/bats-core/bats-core.git --depth=1 -b v1.2.0 bats
- run: bats/bin/bats --tap test

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/bats/
/libexec/pyenv-virtualenv/*/*.class /libexec/pyenv-virtualenv/*/*.class
/libexec/pyenv-virtualenv/*/*.pyc /libexec/pyenv-virtualenv/*/*.pyc
/libexec/pyenv-virtualenv/*/*.pyo /libexec/pyenv-virtualenv/*/*.pyo

View File

@@ -1,5 +1,5 @@
sudo: false sudo: false
install: git clone https://github.com/sstephenson/bats.git install: git clone --depth=1 https://github.com/sstephenson/bats.git
script: bats/bin/bats --tap test script: bats/bin/bats --tap test
language: c language: c
notifications: notifications:

View File

@@ -7,7 +7,7 @@
#### 1.1.4 #### 1.1.4
* Support newer conda (#290) * Support newer conda (#290)
* Prefer `python3.x` executable if avaialble (#206, #282, #296) * Prefer `python3.x` executable if available (#206, #282, #296)
#### 1.1.3 #### 1.1.3

View File

@@ -145,7 +145,7 @@ detect_venv() {
if [ -x "${prefix}/bin/virtualenv" ]; then if [ -x "${prefix}/bin/virtualenv" ]; then
HAS_VIRTUALENV=1 HAS_VIRTUALENV=1
fi fi
# Prefer `python3.x` executable if avaialble (#206, #282) # Prefer `python3.x` executable if available (#206, #282)
local python local python
for python in "python${PYENV_VERSION%.*}" "python${PYENV_VERSION%%.*}" "python"; do for python in "python${PYENV_VERSION%.*}" "python${PYENV_VERSION%%.*}" "python"; do
if pyenv-exec "${python}" -m venv --help 1>/dev/null 2>&1; then if pyenv-exec "${python}" -m venv --help 1>/dev/null 2>&1; then

View File

@@ -75,7 +75,7 @@ else
if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then
PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
unset COMPAT_PREFIX unset COMPAT_PREFIX
else elif [ -z "$FORCE" ]; then
echo "pyenv-virtualenv: \`${DEFINITION}' is not a virtualenv." 1>&2 echo "pyenv-virtualenv: \`${DEFINITION}' is not a virtualenv." 1>&2
exit 1 exit 1
fi fi

View File

@@ -129,7 +129,7 @@ esac
if [[ "$shell" != "fish" ]]; then if [[ "$shell" != "fish" ]]; then
cat <<EOS cat <<EOS
local ret=\$? local ret=\$?
if [ -n "\$VIRTUAL_ENV" ]; then if [ -n "\${VIRTUAL_ENV-}" ]; then
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
else else
eval "\$(pyenv sh-activate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || true)" || true
@@ -141,8 +141,8 @@ EOS
case "$shell" in case "$shell" in
bash ) bash )
cat <<EOS cat <<EOS
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then if ! [[ "\${PROMPT_COMMAND-}" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND"; PROMPT_COMMAND="_pyenv_virtualenv_hook;\${PROMPT_COMMAND-}"
fi fi
EOS EOS
;; ;;

View File

@@ -2,29 +2,33 @@ resolve_link() {
$(type -p greadlink readlink | head -1) "$1" $(type -p greadlink readlink | head -1) "$1"
} }
if [ -n "${DEFINITION}" ]; then uninstall_related_virtual_env() {
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then if [ -n "${DEFINITION}" ]; then
# Uninstall virtualenv by long name if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
exec pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}" # Uninstall virtualenv by long name
exit 128 exec pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}"
else exit 128
VERSION_NAME="${VERSION_NAME:-${DEFINITION##*/}}"
PREFIX="${PREFIX:-${PYENV_ROOT}/versions/${VERSION_NAME}}"
if [ -L "${PREFIX}" ]; then
REAL_PREFIX="$(resolve_link "${PREFIX}" 2>/dev/null || true)"
REAL_DEFINITION="${REAL_PREFIX#${PYENV_ROOT}/versions/}"
if [[ "${REAL_DEFINITION}" != "${REAL_DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by short name
exec pyenv-virtualenv-delete ${FORCE+-f} "${REAL_DEFINITION}"
exit 128
fi
else else
# Uninstall all virtualenvs inside `envs` directory too VERSION_NAME="${VERSION_NAME:-${DEFINITION##*/}}"
shopt -s nullglob PREFIX="${PREFIX:-${PYENV_ROOT}/versions/${VERSION_NAME}}"
for virtualenv in "${PREFIX}/envs/"*; do if [ -L "${PREFIX}" ]; then
pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}/envs/${virtualenv##*/}" REAL_PREFIX="$(resolve_link "${PREFIX}" 2>/dev/null || true)"
done REAL_DEFINITION="${REAL_PREFIX#${PYENV_ROOT}/versions/}"
shopt -u nullglob if [[ "${REAL_DEFINITION}" != "${REAL_DEFINITION%/envs/*}" ]]; then
# Uninstall virtualenv by short name
exec pyenv-virtualenv-delete ${FORCE+-f} "${REAL_DEFINITION}"
exit 128
fi
else
# Uninstall all virtualenvs inside `envs` directory too
shopt -s nullglob
for virtualenv in "${PREFIX}/envs/"*; do
pyenv-virtualenv-delete ${FORCE+-f} "${DEFINITION}/envs/${virtualenv##*/}"
done
shopt -u nullglob
fi
fi fi
fi fi
fi }
before_uninstall "uninstall_related_virtual_env"

View File

@@ -3,7 +3,7 @@
# Usage: . pyenv-virtualenv-realpath # Usage: . pyenv-virtualenv-realpath
if ! { if ! {
enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath || enable -f "${BASH_SOURCE%/*}"/../../../libexec/pyenv-realpath.dylib realpath ||
type realpath type realpath
} >/dev/null 2>&1; then } >/dev/null 2>&1; then
if [ -n "$PYENV_NATIVE_EXT" ]; then if [ -n "$PYENV_NATIVE_EXT" ]; then

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load test_helper load test_helper
@@ -54,7 +54,7 @@ EOS
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv" export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
export PYENV_ACTIVATE_SHELL= export PYENV_ACTIVATE_SHELL=
PYENV_SHELL="bash" run pyenv-sh-deactivate --quit PYENV_SHELL="bash" run pyenv-sh-deactivate --quiet
assert_success assert_success
assert_output <<EOS assert_output <<EOS
@@ -110,36 +110,6 @@ fi;
EOS EOS
} }
@test "deactivate virtualenv (quiet)" {
export PYENV_VIRTUALENV_INIT=1
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
export PYENV_ACTIVATE_SHELL=
PYENV_SHELL="bash" run pyenv-sh-deactivate --quiet
assert_success
assert_output <<EOS
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;
EOS
}
@test "deactivate virtualenv (with shell activation)" { @test "deactivate virtualenv (with shell activation)" {
export PYENV_VIRTUALENV_INIT=1 export PYENV_VIRTUALENV_INIT=1
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv" export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"

View File

@@ -6,7 +6,7 @@ load test_helper
unset PYENV_SHELL unset PYENV_SHELL
SHELL=/bin/false run pyenv-virtualenv-init - SHELL=/bin/false run pyenv-virtualenv-init -
assert_success assert_success
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";' assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
} }
@test "detect parent shell from script (sh)" { @test "detect parent shell from script (sh)" {
@@ -15,7 +15,7 @@ load test_helper
chmod +x ${TMP}/script.sh chmod +x ${TMP}/script.sh
run ${TMP}/script.sh run ${TMP}/script.sh
assert_success assert_success
assert_output_contains_not ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";' assert_output_contains_not ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
rm -f "${TMP}/script.sh" rm -f "${TMP}/script.sh"
} }
@@ -25,7 +25,7 @@ load test_helper
chmod +x ${TMP}/script.sh chmod +x ${TMP}/script.sh
run ${TMP}/script.sh run ${TMP}/script.sh
assert_success assert_success
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";' assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
rm -f "${TMP}/script.sh" rm -f "${TMP}/script.sh"
} }
@@ -54,15 +54,15 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$? local ret=\$?
if [ -n "\$VIRTUAL_ENV" ]; then if [ -n "\${VIRTUAL_ENV-}" ]; then
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
else else
eval "\$(pyenv sh-activate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || true)" || true
fi fi
return \$ret return \$ret
}; };
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then if ! [[ "\${PROMPT_COMMAND-}" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND"; PROMPT_COMMAND="_pyenv_virtualenv_hook;\${PROMPT_COMMAND-}"
fi fi
EOS EOS
} }
@@ -72,6 +72,8 @@ EOS
run pyenv-virtualenv-init - fish run pyenv-virtualenv-init - fish
assert_success assert_success
assert_output <<EOS assert_output <<EOS
while set index (contains -i -- "${TMP}/pyenv/plugins/pyenv-virtualenv/shims" \$PATH)
set -eg PATH[\$index]; end; set -e index
set -gx PATH '${TMP}/pyenv/plugins/pyenv-virtualenv/shims' \$PATH; set -gx PATH '${TMP}/pyenv/plugins/pyenv-virtualenv/shims' \$PATH;
set -gx PYENV_VIRTUALENV_INIT 1; set -gx PYENV_VIRTUALENV_INIT 1;
function _pyenv_virtualenv_hook --on-event fish_prompt; function _pyenv_virtualenv_hook --on-event fish_prompt;
@@ -95,7 +97,7 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$? local ret=\$?
if [ -n "\$VIRTUAL_ENV" ]; then if [ -n "\${VIRTUAL_ENV-}" ]; then
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
else else
eval "\$(pyenv sh-activate --quiet || true)" || true eval "\$(pyenv sh-activate --quiet || true)" || true

View File

@@ -63,7 +63,7 @@ OUT
assert_success assert_success
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=3.3.6 python3.3 -m venv ${PYENV_ROOT}/versions/3.3.6/envs/venv PYENV_VERSION=3.3.6 python3.3 -m venv ${PYENV_ROOT}/versions/3.3.6/envs/venv
Installing pip from https://bootstrap.pypa.io/3.3/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/3.3/get-pip.py...
PYENV_VERSION=3.3.6/envs/venv python -s ${TMP}/pyenv/cache/get-pip.py PYENV_VERSION=3.3.6/envs/venv python -s ${TMP}/pyenv/cache/get-pip.py
rehashed rehashed
OUT OUT

View File

@@ -74,8 +74,10 @@ assert_failure() {
assert_equal() { assert_equal() {
if [ "$1" != "$2" ]; then if [ "$1" != "$2" ]; then
{ echo "expected: $1" { echo "expected:"
echo "actual: $2" echo "$1"
echo "actual:"
echo "$2"
} | flunk } | flunk
fi fi
} }

View File

@@ -38,7 +38,7 @@ unstub_pyenv() {
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
rehashed rehashed
OUT OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ] assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
@@ -67,7 +67,7 @@ OUT
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
rehashed rehashed
OUT OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ] assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
@@ -97,7 +97,7 @@ OUT
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/versions/2.7.11/envs/venv PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
rehashed rehashed
OUT OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ] assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
@@ -127,7 +127,7 @@ OUT
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/versions/2.7.11/envs/venv PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
rehashed rehashed
OUT OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ] assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
@@ -192,7 +192,7 @@ OUT
assert_output <<OUT assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/foo PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/foo
Installing pip from https://bootstrap.pypa.io/get-pip.py... Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
rehashed rehashed
OUT OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/foo/bin/pydoc" ] assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/foo/bin/pydoc" ]