Skip to content

Commit 0f81bbf

Browse files
committed
Add composer and golang versions
And also support gitlab native ranges for them Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 56990bf commit 0f81bbf

5 files changed

Lines changed: 19888 additions & 3 deletions

File tree

src/univers/version_range.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,16 @@ class ComposerVersionRange(VersionRange):
664664
# TODO composer may need its own scheme see https//github.com/nexB/univers/issues/5
665665
# and https//getcomposer.org/doc/articles/versions.md
666666
scheme = "composer"
667-
version_class = versions.SemverVersion
667+
version_class = versions.ComposerVersion
668+
669+
vers_by_native_comparators = {
670+
"==": "=",
671+
"<=": "<=",
672+
">=": ">=",
673+
"<": "<",
674+
">": ">",
675+
"=": "=", # This is not a native composer-semver comparator, but is used in the gitlab version range for composer packages.
676+
}
668677

669678

670679
class RpmVersionRange(VersionRange):
@@ -757,7 +766,16 @@ class GolangVersionRange(VersionRange):
757766
"""
758767

759768
scheme = "golang"
760-
version_class = versions.SemverVersion
769+
version_class = versions.GolangVersion
770+
771+
vers_by_native_comparators = {
772+
"==": "=",
773+
"<=": "<=",
774+
">=": ">=",
775+
"<": "<",
776+
">": ">",
777+
"=": "=", # This is not a native golang-semver comparator, but is used in the gitlab version range for go packages.
778+
}
761779

762780

763781
class GenericVersionRange(VersionRange):
@@ -980,7 +998,8 @@ def from_gitlab_native(cls, scheme, string):
980998
constraint_items = []
981999
constraints = []
9821000
split = " "
983-
if scheme == "pypi":
1001+
split_by_comma_schemes = ["pypi", "composer"]
1002+
if scheme in split_by_comma_schemes:
9841003
split = ","
9851004
pipe_separated_constraints = string.split("||")
9861005
for pipe_separated_constraint in pipe_separated_constraints:

src/univers/versions.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,38 @@ def __gt__(self, other):
427427
return gentoo.vercmp(self.value, other.value) > 0
428428

429429

430+
@attr.s(frozen=True, order=False, eq=False, hash=True)
431+
class ComposerVersion(SemverVersion):
432+
@classmethod
433+
def build_value(cls, string):
434+
string = string.lstrip("vV")
435+
return SemverVersion(string=string)
436+
437+
@classmethod
438+
def is_valid(cls, string):
439+
try:
440+
cls.build_value(string)
441+
return True
442+
except ValueError:
443+
return False
444+
445+
446+
@attr.s(frozen=True, order=False, eq=False, hash=True)
447+
class GolangVersion(SemverVersion):
448+
@classmethod
449+
def build_value(cls, string):
450+
string = string.lstrip("vV")
451+
return SemverVersion(string=string)
452+
453+
@classmethod
454+
def is_valid(cls, string):
455+
try:
456+
cls.build_value(string)
457+
return True
458+
except ValueError:
459+
return False
460+
461+
430462
@attr.s(frozen=True, order=False, eq=False, hash=True)
431463
class LegacyOpensslVersion(Version):
432464
"""

0 commit comments

Comments
 (0)