Skip to content

Commit

Permalink
Support a prefix resolved by pyenv-latest as base version (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
native-api authored Jan 29, 2023
1 parent d5f2878 commit a6ab660
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/pyenv-virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ else
VIRTUALENV_NAME="${ARGUMENTS[1]}"
fi

if [[ -n "${VERSION_NAME}" ]] && command -v pyenv-latest >/dev/null; then
VERSION_NAME="$(pyenv-latest -q "${VERSION_NAME}" || echo "${VERSION_NAME}")"
fi

if [ -z "${VERSION_NAME}" ] || [ -z "${VIRTUALENV_NAME}" ]; then
usage 1
fi
Expand Down
29 changes: 29 additions & 0 deletions test/virtualenv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ OUT
unstub curl
}

@test "create virtualenv from a given prefix" {
stub_pyenv "2.7.11"
stub pyenv-virtualenv-prefix " : false"
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 "python -s -m ensurepip : false"
stub pyenv-exec "python -s */get-pip.py : true"
stub curl true
stub pyenv-latest "-q 2.7 : echo 2.7.11"

run pyenv-virtualenv "2.7" "venv"

assert_output <<OUT
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 [ ! -e "${PYENV_ROOT}/versions/2.7" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
unstub pyenv-exec
unstub curl
}

@test "create virtualenv from current version" {
export PYENV_VERSION="2.7.11"
stub_pyenv "${PYENV_VERSION}"
Expand Down

0 comments on commit a6ab660

Please sign in to comment.