Skip to content

Support prefixes resolved by pyenv-latest as base version names #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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