@@ -233,6 +233,7 @@ class NpmVersionRange(VersionRange):
233233 ">=" : ">=" ,
234234 "<" : "<" ,
235235 ">" : ">" ,
236+ "=" : "=" , # This is not a native node-semver comparator, but is used in the gitlab version range for npm packages.
236237 }
237238
238239 @classmethod
@@ -972,6 +973,51 @@ def from_native(cls, string):
972973 return cls (constraints = constraints )
973974
974975
976+ class GitLabVersionRange (VersionRange ):
977+ @classmethod
978+ def from_gitlab_native (cls , scheme , string ):
979+ vrc = RANGE_CLASS_BY_SCHEMES [scheme ]
980+ constraint_items = []
981+ constraints = []
982+ split = " "
983+ if scheme == "pypi" :
984+ split = ","
985+ pipe_separated_constraints = string .split ("||" )
986+ for pipe_separated_constraint in pipe_separated_constraints :
987+ space_seperated_constraints = pipe_separated_constraint .split (split )
988+ constraint_items .extend (space_seperated_constraints )
989+ comparator = ""
990+ # A constraint item can be a comparator or a version or a version with comparator
991+ # If it's empty continue
992+ # If it's in `vers_by_native_comparators`, append it with the comparator and continue
993+ # If it's a version, make version constraint from the version and use the comparator from the previous item and make comparator empty
994+ # If it's a version with comparator, use split_req to get version and comparator to form constraint and make comparator empty
995+ for constraint_item in constraint_items :
996+ if not constraint_item :
997+ continue
998+ if "" .join ([comparator , constraint_item ]) in vrc .vers_by_native_comparators :
999+ comparator = "" .join ([comparator , constraint_item ])
1000+ comparator = vrc .vers_by_native_comparators [comparator ]
1001+ continue
1002+ if comparator :
1003+ constraints .append (
1004+ VersionConstraint (
1005+ comparator = comparator , version = vrc .version_class (constraint_item )
1006+ )
1007+ )
1008+ else :
1009+ comparator , version_constraint = split_req (
1010+ constraint_item , vrc .vers_by_native_comparators
1011+ )
1012+ constraints .append (
1013+ VersionConstraint (
1014+ comparator = comparator , version = vrc .version_class (version_constraint )
1015+ )
1016+ )
1017+ comparator = ""
1018+ return vrc (constraints = constraints )
1019+
1020+
9751021vers_by_github_native_comparators = {
9761022 "=" : "=" ,
9771023 "!=" : "!=" ,
0 commit comments