Skip to content

Commit a6ab660

Browse files
authored
Support a prefix resolved by pyenv-latest as base version (#446)
1 parent d5f2878 commit a6ab660

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

bin/pyenv-virtualenv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ else
310310
VIRTUALENV_NAME="${ARGUMENTS[1]}"
311311
fi
312312

313+
if [[ -n "${VERSION_NAME}" ]] && command -v pyenv-latest >/dev/null; then
314+
VERSION_NAME="$(pyenv-latest -q "${VERSION_NAME}" || echo "${VERSION_NAME}")"
315+
fi
316+
313317
if [ -z "${VERSION_NAME}" ] || [ -z "${VIRTUALENV_NAME}" ]; then
314318
usage 1
315319
fi

test/virtualenv.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,35 @@ OUT
5050
unstub curl
5151
}
5252

53+
@test "create virtualenv from a given prefix" {
54+
stub_pyenv "2.7.11"
55+
stub pyenv-virtualenv-prefix " : false"
56+
stub pyenv-exec "python2.7 -m venv --help : false"
57+
stub pyenv-exec "python2 -m venv --help : false"
58+
stub pyenv-exec "python -m venv --help : false"
59+
stub pyenv-exec "virtualenv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
60+
stub pyenv-exec "python -s -m ensurepip : false"
61+
stub pyenv-exec "python -s */get-pip.py : true"
62+
stub curl true
63+
stub pyenv-latest "-q 2.7 : echo 2.7.11"
64+
65+
run pyenv-virtualenv "2.7" "venv"
66+
67+
assert_output <<OUT
68+
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
69+
Installing pip from https://bootstrap.pypa.io/pip/2.7/get-pip.py...
70+
rehashed
71+
OUT
72+
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
73+
assert [ ! -e "${PYENV_ROOT}/versions/2.7" ]
74+
assert_success
75+
76+
unstub_pyenv
77+
unstub pyenv-virtualenv-prefix
78+
unstub pyenv-exec
79+
unstub curl
80+
}
81+
5382
@test "create virtualenv from current version" {
5483
export PYENV_VERSION="2.7.11"
5584
stub_pyenv "${PYENV_VERSION}"

0 commit comments

Comments
 (0)