-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
With the introduction of 3.10, the sorting of versions is no longer intuitively correct.
$ pyenv versions
* system
3.10.0
3.9.7
This seems to happen as a side effect of glob expansion sorting on a byte for byte basis on most filesystems.
Line 135 in fab0082
| for env_path in "${path}/envs/"*; do |
GNU sort would have a -V --version-sort [1] flag, but that's not portable as at least sort on macOS does not have that [2].
Columnar sort with a separator [2]could be a way to approach the problem. This could be added as a pipe to the end of that for loop.
This is the path the --definitions command of python-build has taken.
pyenv/plugins/python-build/bin/python-build
Lines 1825 to 1830 in fab0082
| list_definitions() { | |
| { for DEFINITION_DIR in "${PYTHON_BUILD_DEFINITIONS[@]}"; do | |
| [ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR" | grep -xv patches | |
| done | |
| } | sort_versions | uniq | |
| } |
pyenv/plugins/python-build/bin/python-build
Lines 1832 to 1835 in fab0082
| sort_versions() { | |
| sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \ | |
| LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' | |
| } |
[1] https://man7.org/linux/man-pages/man1/sort.1.html
[2] https://ss64.com/osx/sort.html
[3] https://stackoverflow.com/a/39454220/1214697