mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Import recent changes from rbenv-versions
This commit is contained in:
parent
77bd5bc6c9
commit
8e657374a1
2 changed files with 45 additions and 8 deletions
|
@ -11,7 +11,6 @@ if [ "$1" = "--bare" ]; then
|
||||||
hit_prefix=""
|
hit_prefix=""
|
||||||
miss_prefix=""
|
miss_prefix=""
|
||||||
current_versions=()
|
current_versions=()
|
||||||
version_origin=""
|
|
||||||
include_system=""
|
include_system=""
|
||||||
else
|
else
|
||||||
hit_prefix="* "
|
hit_prefix="* "
|
||||||
|
@ -19,25 +18,30 @@ else
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: current_versions=($(pyenv-version-name || true))
|
IFS=: current_versions=($(pyenv-version-name || true))
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
version_origin=" (set by $(pyenv-version-origin))"
|
|
||||||
include_system="1"
|
include_system="1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
array_exists() {
|
num_versions=0
|
||||||
local x car="$1"
|
|
||||||
|
exists() {
|
||||||
|
local car="$1"
|
||||||
|
local cdar
|
||||||
shift
|
shift
|
||||||
for x in "$@"; do
|
for cdar in "$@"; do
|
||||||
[ "${x}" = "${car}" ] && return 0
|
if [ "${car}" == "${cdar}" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
print_version() {
|
print_version() {
|
||||||
if array_exists "$1" "${current_versions[@]}"; then
|
if exists "$1" "${current_versions[@]}"; then
|
||||||
echo "${hit_prefix}$1${version_origin}"
|
echo "${hit_prefix}$1 (set by $(pyenv-version-origin))"
|
||||||
else
|
else
|
||||||
echo "${miss_prefix}$1"
|
echo "${miss_prefix}$1"
|
||||||
fi
|
fi
|
||||||
|
num_versions=$((num_versions + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Include "system" in the non-bare output, if it exists
|
# Include "system" in the non-bare output, if it exists
|
||||||
|
@ -45,8 +49,15 @@ if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/nul
|
||||||
print_version system
|
print_version system
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
for path in "${PYENV_ROOT}/versions/"*; do
|
for path in "${PYENV_ROOT}/versions/"*; do
|
||||||
if [ -d "$path" ]; then
|
if [ -d "$path" ]; then
|
||||||
print_version "${path##*/}"
|
print_version "${path##*/}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then
|
||||||
|
echo "Warning: no Python detected on the system" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -24,6 +24,12 @@ stub_system_python() {
|
||||||
assert_success "* system (set by ${PYENV_ROOT}/version)"
|
assert_success "* system (set by ${PYENV_ROOT}/version)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "not even system python available" {
|
||||||
|
PATH="$(path_without python)" run pyenv-versions
|
||||||
|
assert_failure
|
||||||
|
assert_output "Warning: no Python detected on the system"
|
||||||
|
}
|
||||||
|
|
||||||
@test "bare output no versions installed" {
|
@test "bare output no versions installed" {
|
||||||
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
||||||
run pyenv-versions --bare
|
run pyenv-versions --bare
|
||||||
|
@ -113,3 +119,23 @@ OUT
|
||||||
3.4.0
|
3.4.0
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "ignores non-directories under versions" {
|
||||||
|
create_version "3.3"
|
||||||
|
touch "${PYENV_ROOT}/versions/hello"
|
||||||
|
|
||||||
|
run pyenv-versions --bare
|
||||||
|
assert_success "3.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lists symlinks under versions" {
|
||||||
|
create_version "2.7.8"
|
||||||
|
ln -s "2.7.8" "${PYENV_ROOT}/versions/2.7"
|
||||||
|
|
||||||
|
run pyenv-versions --bare
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
2.7
|
||||||
|
2.7.8
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue