URL: https://github.com/freeipa/freeipa/pull/254
Title: #254: Replace LooseVersion with pkg_resources.parse_version

tiran commented:
"""
sigh, you are right, parse_version does not handle one version comparison as we 
expect: ```4.2.0-15.el7 < 4.2.0-15.el7_2.3``` 

```
from __future__ import print_function
import operator
import pkg_resources


version_strings = [
    ("3.0.0-1.el6", "3.0.0-2.el6", operator.lt),
    ("3.0.0-1.el6_8", "3.0.0-1.el6_8.1", operator.lt),
    ("3.0.0-42.el6", "3.0.0-1.el6", operator.gt),
    ("3.0.0-1.el6", "3.0.0-42.el6", operator.lt),
    ("3.0.0-42.el6", "3.3.3-1.fc20", operator.lt),
    ("4.2.0-15.el7", "4.2.0-15.el7_2.3", operator.lt),
    ("4.2.0-15.el7_2", "4.2.0-15.el7_2.3", operator.lt),
    ("4.2.0-15.el7_2.3", "4.2.0-15.el7_2.3", operator.eq),
    ("4.2.0-15.el7_2.3", "4.2.0-15.el7_2.2", operator.gt),
    ("4.2.0-1.fc23", "4.2.1-1.fc23", operator.lt),
    ("4.2.3-alpha1.fc23", "4.2.3-2.fc23", operator.lt),
    ("4.3.90.201601080923GIT55aeea7-0.fc23", "4.3.0-1.fc23", operator.gt)
]

for v1, v2, op in version_strings:
    v1 = pkg_resources.parse_version(v1)
    v2 = pkg_resources.parse_version(v2)
    if not op(v1, v2):
        print("failure: ", v1, op.__name__, v2)
```

```
$ python v.py 
failure:  4.2.0-15.el7 lt 4.2.0-15.el7_2.3
```
"""

See the full comment at 
https://github.com/freeipa/freeipa/pull/254#issuecomment-261491515
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to