Skip to content

Commit 85d8c5a

Browse files
More helpful error message when env's base version is not installed (#454)
1 parent fca1241 commit 85d8c5a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

bin/pyenv-virtualenv

+13-2
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,20 @@ fi
336336
# Set VERSION_NAME as default version in this script
337337
export PYENV_VERSION="${VERSION_NAME}"
338338

339+
not_installed_message() {
340+
local is_available=$(python-build --definitions | grep -F -x "$1")
341+
echo "pyenv-virtualenv: \`${1}' is not installed in pyenv." 1>&2
342+
if [[ $is_available ]]; then
343+
echo "Run \`pyenv install ${1}' to install it." 1>&2
344+
else
345+
echo "It does not look like a valid Python version. See \`pyenv install --list' for available versions." 1>&2
346+
fi
347+
}
348+
339349
# Source version must exist before creating virtualenv.
340350
PREFIX="$(pyenv-prefix 2>/dev/null || true)"
341351
if [ ! -d "${PREFIX}" ]; then
342-
echo "pyenv-virtualenv: \`${PYENV_VERSION}' is not installed in pyenv." 1>&2
352+
not_installed_message "${PYENV_VERSION}"
343353
exit 1
344354
fi
345355

@@ -441,7 +451,8 @@ else
441451
if [ -x "${python}" ]; then
442452
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${python}"
443453
else
444-
echo "pyenv-virtualenv: \`${VIRTUALENV_PYTHON##*/}' is not installed in pyenv." 1>&2
454+
# echo "pyenv-virtualenv: \`${VIRTUALENV_PYTHON##*/}' is not installed in pyenv." 1>&2
455+
not_installed_message "${VIRTUALENV_PYTHON##*/}"
445456
exit 1
446457
fi
447458
fi

test/python.bats

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ setup() {
1414
stub pyenv-rehash " : true"
1515
stub pyenv-version-name "echo \${PYENV_VERSION}"
1616
stub curl true
17+
stub python-build "echo python2.7"
1718
}
1819

1920
teardown() {
@@ -22,6 +23,7 @@ teardown() {
2223
unstub pyenv-prefix
2324
unstub pyenv-hooks
2425
unstub pyenv-rehash
26+
unstub python-build
2527
teardown_version "2.7.8"
2628
rm -fr "$TMP"/*
2729
}
@@ -96,6 +98,7 @@ OUT
9698

9799
assert_output <<OUT
98100
pyenv-virtualenv: \`python2.7' is not installed in pyenv.
101+
Run \`pyenv install python2.7' to install it.
99102
OUT
100103
assert_failure
101104

@@ -106,3 +109,13 @@ OUT
106109
remove_executable "2.7.8" "python2.7"
107110
remove_executable "2.7.9" "python2.7"
108111
}
112+
113+
@test "invalid python name" {
114+
run pyenv-virtualenv --verbose --python=99.99.99 venv
115+
116+
assert_output <<OUT
117+
pyenv-virtualenv: \`99.99.99' is not installed in pyenv.
118+
It does not look like a valid Python version. See \`pyenv install --list' for available versions.
119+
OUT
120+
assert_failure
121+
}

0 commit comments

Comments
 (0)