Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1175
version ordering in opam is a bit specific
Active
Public
Actions
Authored by
ardumont
on Sep 24 2021, 4:14 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
Case with some edge cases:
```
$ opam show --color never --normalise --root $PWD -f all-versions opam-state
2.0~alpha5 2.0.0~beta 2.0.0~beta3 2.0.0~beta3.1 2.0.0~beta5 2.0.0~rc 2.0.0~rc2 2.0.0~rc3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0~beta2 2.1.0~beta4 2.1.0~rc 2.1.0~rc2 2.1.0
```
The default python ordering does not work as is, due to the ~ most likely [1]:
```
In [1]: versions = ["2.0~alpha5",
...: "2.0.0~beta",
...: "2.0.0~beta3",
...: "2.0.0~beta3.1",
...: "2.0.0~beta5",
...: "2.0.0~rc",
...: "2.0.0~rc2",
...: "2.0.0~rc3",
...: "2.0.0",
...: "2.0.1",
...: "2.0.2",
...: "2.0.3",
...: "2.0.4",
...: "2.0.5",
...: "2.0.6",
...: "2.0.7",
...: "2.0.8",
...: "2.0.9",
...: "2.1.0~beta2",
...: "2.1.0~beta4",
...: "2.1.0~rc",
...: "2.1.0~rc2",
...: "2.1.0"]
In [2]: versions2 = versions.copy()
In [3]: versions2.sort()
In [5]: versions2 == versions # ------------> default ordering says no
Out[5]: False
In [12]: from packaging.version import Version, parse
In [13]: parse("2.0~alpha5")
Out[13]: <LegacyVersion('2.0~alpha5')>
In [14]: versions2 = sorted(versions, key=parse)
In [24]: versions2
Out[24]:
['2.0~alpha5',
'2.0.0~beta',
'2.0.0~beta3',
'2.0.0~beta3.1',
'2.0.0~beta5',
'2.0.0~rc',
'2.0.0~rc2',
'2.0.0~rc3',
'2.1.0~beta2',
'2.1.0~beta4',
'2.1.0~rc',
'2.1.0~rc2',
'2.0.0',
'2.0.1',
'2.0.2',
'2.0.3',
'2.0.4',
'2.0.5',
'2.0.6',
'2.0.7',
'2.0.8',
'2.0.9',
'2.1.0']
In [25]: versions2 == versions # ----> another tryout fails to compare as well
Out[25]:
False
```
[1] https://github.com/ocaml/opam/blob/master/src/core/opamVersionCompare.ml#L58-L61
Event Timeline
ardumont
created this paste.
Sep 24 2021, 4:14 PM
2021-09-24 16:14:30 (UTC+2)
Log In to Comment