mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Merge pull request #290 from blueyed/version-handle-missing-better
Improve `pyenv version`, if there is one missing
This commit is contained in:
commit
46ffb0c8df
4 changed files with 77 additions and 2 deletions
|
@ -8,10 +8,13 @@
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
exitcode=0
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name))
|
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
|
for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
|
||||||
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
|
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
exit $exitcode
|
||||||
|
|
|
@ -21,6 +21,7 @@ version_exists() {
|
||||||
versions=()
|
versions=()
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
{ IFS=:
|
{ IFS=:
|
||||||
|
any_not_installed=0
|
||||||
for version in ${PYENV_VERSION}; do
|
for version in ${PYENV_VERSION}; do
|
||||||
if version_exists "$version" || [ "$version" = "system" ]; then
|
if version_exists "$version" || [ "$version" = "system" ]; then
|
||||||
versions=("${versions[@]}" "${version}")
|
versions=("${versions[@]}" "${version}")
|
||||||
|
@ -28,7 +29,7 @@ OLDIFS="$IFS"
|
||||||
versions=("${versions[@]}" "${version#python-}")
|
versions=("${versions[@]}" "${version#python-}")
|
||||||
else
|
else
|
||||||
echo "pyenv: version \`$version' is not installed" >&2
|
echo "pyenv: version \`$version' is not installed" >&2
|
||||||
exit 1
|
any_not_installed=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -39,3 +40,7 @@ OLDIFS="$IFS"
|
||||||
echo "${versions[*]}"
|
echo "${versions[*]}"
|
||||||
}
|
}
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
|
if [ "$any_not_installed" = 1 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -52,6 +52,39 @@ setup() {
|
||||||
assert_failure "pyenv: version \`1.2' is not installed"
|
assert_failure "pyenv: version \`1.2' is not installed"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "one missing version (second missing)" {
|
||||||
|
create_version "3.4.2"
|
||||||
|
PYENV_VERSION="3.4.2:1.2" run pyenv-version-name
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
pyenv: version \`1.2' is not installed
|
||||||
|
3.4.2
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "one missing version (first missing)" {
|
||||||
|
create_version "3.4.2"
|
||||||
|
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
pyenv: version \`1.2' is not installed
|
||||||
|
3.4.2
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
pyenv-version-name-without-stderr() {
|
||||||
|
pyenv-version-name 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "one missing version (without stderr)" {
|
||||||
|
create_version "3.4.2"
|
||||||
|
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name-without-stderr
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
3.4.2
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
@test "version with prefix in name" {
|
@test "version with prefix in name" {
|
||||||
create_version "2.7.6"
|
create_version "2.7.6"
|
||||||
cat > ".python-version" <<<"python-2.7.6"
|
cat > ".python-version" <<<"python-2.7.6"
|
||||||
|
|
|
@ -36,3 +36,37 @@ setup() {
|
||||||
run pyenv-version
|
run pyenv-version
|
||||||
assert_success "3.3.3 (set by ${PYENV_ROOT}/version)"
|
assert_success "3.3.3 (set by ${PYENV_ROOT}/version)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "set by PYENV_VERSION, one missing" {
|
||||||
|
create_version "3.3.3"
|
||||||
|
PYENV_VERSION=3.3.3:1.2 run pyenv-version
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
pyenv: version \`1.2' is not installed
|
||||||
|
3.3.3 (set by PYENV_VERSION environment variable)
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set by PYENV_VERSION, two missing" {
|
||||||
|
create_version "3.3.3"
|
||||||
|
PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
pyenv: version \`3.4.2' is not installed
|
||||||
|
pyenv: version \`1.2' is not installed
|
||||||
|
3.3.3 (set by PYENV_VERSION environment variable)
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
pyenv-version-without-stderr() {
|
||||||
|
pyenv-version 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set by PYENV_VERSION, one missing (stderr filtered)" {
|
||||||
|
create_version "3.3.3"
|
||||||
|
PYENV_VERSION=3.4.2:3.3.3 run pyenv-version-without-stderr
|
||||||
|
assert_failure
|
||||||
|
assert_output <<OUT
|
||||||
|
3.3.3 (set by PYENV_VERSION environment variable)
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue