mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Use version sort in pyenv versions
if available (#2405)
This commit is contained in:
parent
207f33fc5e
commit
fdaeaf1f97
2 changed files with 62 additions and 1 deletions
|
@ -123,7 +123,19 @@ if [ -n "$include_system" ] && \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shopt -s dotglob nullglob
|
shopt -s dotglob nullglob
|
||||||
for path in "$versions_dir"/*; do
|
versions_dir_entries=("$versions_dir"/*)
|
||||||
|
if sort --version-sort </dev/null >/dev/null 2>&1; then
|
||||||
|
# system sort supports version sorting
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
IFS=$'\n'
|
||||||
|
versions_dir_entries=($(
|
||||||
|
printf "%s\n" "${versions_dir_entries[@]}" |
|
||||||
|
sort --version-sort
|
||||||
|
))
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for path in "${versions_dir_entries[@]}"; do
|
||||||
if [ -d "$path" ]; then
|
if [ -d "$path" ]; then
|
||||||
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
||||||
target="$(realpath "$path")"
|
target="$(realpath "$path")"
|
||||||
|
|
|
@ -17,6 +17,14 @@ stub_system_python() {
|
||||||
touch "$stub" && chmod +x "$stub"
|
touch "$stub" && chmod +x "$stub"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_executable() {
|
||||||
|
local name="$1"
|
||||||
|
local bin="${PYENV_TEST_DIR}/bin"
|
||||||
|
mkdir -p "$bin"
|
||||||
|
sed -Ee '1s/^ +//' > "${bin}/$name"
|
||||||
|
chmod +x "${bin}/$name"
|
||||||
|
}
|
||||||
|
|
||||||
@test "no versions installed" {
|
@test "no versions installed" {
|
||||||
stub_system_python
|
stub_system_python
|
||||||
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
||||||
|
@ -161,3 +169,44 @@ OUT
|
||||||
run pyenv-versions --bare
|
run pyenv-versions --bare
|
||||||
assert_success ".venv"
|
assert_success ".venv"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "sort supports version sorting" {
|
||||||
|
create_version "1.9.0"
|
||||||
|
create_version "1.53.0"
|
||||||
|
create_version "1.218.0"
|
||||||
|
create_executable sort <<SH
|
||||||
|
#!$BASH
|
||||||
|
if [ "\$1" == "--version-sort" ]; then
|
||||||
|
echo "${PYENV_ROOT}/versions/1.9.0"
|
||||||
|
echo "${PYENV_ROOT}/versions/1.53.0"
|
||||||
|
echo "${PYENV_ROOT}/versions/1.218.0"
|
||||||
|
else exit 1
|
||||||
|
fi
|
||||||
|
SH
|
||||||
|
|
||||||
|
run pyenv-versions --bare
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
1.9.0
|
||||||
|
1.53.0
|
||||||
|
1.218.0
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "sort doesn't support version sorting" {
|
||||||
|
create_version "1.9.0"
|
||||||
|
create_version "1.53.0"
|
||||||
|
create_version "1.218.0"
|
||||||
|
create_executable sort <<SH
|
||||||
|
#!$BASH
|
||||||
|
exit 1
|
||||||
|
SH
|
||||||
|
|
||||||
|
run pyenv-versions --bare
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
1.218.0
|
||||||
|
1.53.0
|
||||||
|
1.9.0
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue