Skip to content

Commit 0fc20b6

Browse files
committed
Temporary fix for semver-unstable sort
- Revert this once this is fixed in upstream - rbarrois/python-semanticversion#132 Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent df34260 commit 0fc20b6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/univers/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download.
66

7+
import semantic_version
8+
79

810
def remove_spaces(string):
911
return "".join(string.split())
@@ -27,3 +29,15 @@ def cmp(x, y):
2729
else:
2830
# note that this is the minimal replacement function
2931
return (x > y) - (x < y)
32+
33+
34+
class SortableSemverVersion(semantic_version.Version):
35+
"""
36+
TODO: This is temporary workaround for unstable sort
37+
Revert this and associated changes once the upstream is fixed.
38+
https://github.com/rbarrois/python-semanticversion/issues/132
39+
"""
40+
41+
@property
42+
def precedence_key(self):
43+
return super().precedence_key + (self.build,)

src/univers/versions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import functools
99

1010
import attr
11-
import semantic_version
11+
from univers.utils import SortableSemverVersion
1212
from packaging import version as packaging_version
1313

1414
from univers import arch
@@ -209,7 +209,7 @@ class SemverVersion(Version):
209209

210210
@classmethod
211211
def build_value(cls, string):
212-
return semantic_version.Version.coerce(string)
212+
return SortableSemverVersion.coerce(string)
213213

214214
@classmethod
215215
def is_valid(cls, string):
@@ -431,14 +431,14 @@ def __gt__(self, other):
431431
class ComposerVersion(SemverVersion):
432432
@classmethod
433433
def build_value(cls, string):
434-
return semantic_version.Version.coerce(string.lstrip("vV"))
434+
return SortableSemverVersion.coerce(string.lstrip("vV"))
435435

436436

437437
@attr.s(frozen=True, order=False, eq=False, hash=True)
438438
class GolangVersion(SemverVersion):
439439
@classmethod
440440
def build_value(cls, string):
441-
return semantic_version.Version.coerce(string.lstrip("vV"))
441+
return SortableSemverVersion.coerce(string.lstrip("vV"))
442442

443443

444444
@attr.s(frozen=True, order=False, eq=False, hash=True)
@@ -605,7 +605,7 @@ def is_valid_new(cls, string):
605605
True
606606
"""
607607
if SemverVersion.is_valid(string):
608-
sem = semantic_version.Version.coerce(string)
608+
sem = SortableSemverVersion.coerce(string)
609609
return sem.major >= 3
610610

611611
@classmethod

0 commit comments

Comments
 (0)