For the moment, the autocompletion of the package versions make the list of versions appear sorted in an alphabetical way.
This leads to have a list like :
Because 2 is considered before 9.
To sort the versions, the UI needs to perform some operations to split the parts of the version.
Following the previous example, by splitting on the dot :
1.9.0. ➞ Major 1, minor 9, revision 0
1.22.0 ➞ Major 1, minor 22, revision 0
1.1.2 ➞ Major 1, minor 1, revision 2
And then, if we order by Major descending, minor descending, and revision descending, we get the right sort :
1.22.0 ➞ Major 1, minor 22, revision 0
1.9.0. ➞ Major 1, minor 9, revision 0
1.1.2 ➞ Major 1, minor 1, revision 2
Unfortunately, not all the versions are following this pattern.
Some version numbers have 4 dots, or underscores, or even texts.
Recipe :
So, here is a recipe to sort the version numbers (The version numbers will appear unmodified in the list, use this only to perform the sort) :
- if the version number starts with a "v" (like "v1.2.3"), remove it
- split all the version numbers on the dots and underscores.
- convert each value to integers. If there are any non-numeric characters, remove them
in the end, for each version number, you'll have something like a list of integers. Consider the first one as the Major, the second one as the minor, etc, and use this list to sort the versions accordingly.
Example
Example with Numpy's versions :
Considers the list of versions of numpy :
"1.10.4", "1.11.0", "1.11.1", "1.11.2", "1.11.3", "1.12.0", ... "1.22.0", "1.22.1", "1.22.2", "1.22.3", "1.22.4", "1.23.0", "1.23.1", "1.23.2", "1.23.3", "1.7.2", "1.8.2", "1.9.3"
By applying the above recipy, we get the following list of integers for each version (not sorted yet)
"1.10.4" ➞ [1, 10, 4]
"1.11.0" ➞ [1, 11, 0]
"1.11.1" ➞ [1, 11, 1]
"1.11.2" ➞ [1, 11, 2]
"1.11.3" ➞ [1, 11, 3]
"1.12.0" ➞ [1, 12, 0]
...
"1.20.0" ➞ [1, 20, 0]
...
"1.20.3" ➞ [1, 20, 3]
"1.21.0" ➞ [1, 21, 0]
"1.21.1" ➞ [1, 21, 1]
...
"1.21.6" ➞ [1, 21, 6]
"1.22.0" ➞ [1, 22, 0]
...
"1.22.4" ➞ [1, 22, 4]
"1.23.0" ➞ [1, 23, 0]
"1.23.1" ➞ [1, 23, 1]
"1.23.2" ➞ [1, 23, 2]
"1.23.3" ➞ [1, 23, 3]
"1.7.2" ➞ [1 ,7, 2]
"1.8.2" ➞ [1 ,8, 2]
"1.9.3" ➞ [1 ,9, 3]
Now, by sorting the versions according to their list of integers, in a decreasing way, we'll get the list sorted as expected :
['1.23.3', '1.23.2', '1.23.1', '1.23.0', '1.22.4', '1.22.3', '1.22.2', '1.22.1', '1.22.0', '1.21.6', '1.21.5', '1.21.4', '1.21.3', '1.21.2', '1.21.1', '1.21.0', '1.20.3', '1.20.2', '1.20.1', '1.20.0', '1.19.5', '1.19.4', '1.19.2', '1.19.1', '1.19.0', '1.18.5', '1.18.4', '1.18.1', '1.17.5', '1.17.3', '1.17.2', '1.17.1', '1.17.0', '1.16.6', '1.16.5', '1.16.4', '1.16.3', '1.16.2', '1.16.1', '1.16.0', '1.15.4', '1.15.3', '1.15.2', '1.15.1', '1.15.0', '1.14.6', '1.14.5', '1.14.4', '1.14.3', '1.14.2', '1.14.1', '1.14.0', '1.13.3', '1.13.2', '1.13.1', '1.13.0', '1.12.1', '1.12.0', '1.11.3', '1.11.2', '1.11.1', '1.11.0', '1.10.4', '1.9.3', '1.8.2', '1.7.2']