@@ -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
670679class 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
763781class GenericVersionRange (VersionRange ):
@@ -973,49 +991,46 @@ def from_native(cls, string):
973991 return cls (constraints = constraints )
974992
975993
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- )
994+ def from_gitlab_native (scheme , string ):
995+ vrc = RANGE_CLASS_BY_SCHEMES [scheme ]
996+ constraint_items = []
997+ constraints = []
998+ split = " "
999+ split_by_comma_schemes = ["pypi" , "composer" ]
1000+ if scheme in split_by_comma_schemes :
1001+ split = ","
1002+ pipe_separated_constraints = string .split ("||" )
1003+ for pipe_separated_constraint in pipe_separated_constraints :
1004+ space_seperated_constraints = pipe_separated_constraint .split (split )
1005+ constraint_items .extend (space_seperated_constraints )
1006+ comparator = ""
1007+ # A constraint item can be a comparator or a version or a version with comparator
1008+ # If it's empty continue
1009+ # If it's in `vers_by_native_comparators`, append it with the comparator and continue
1010+ # If it's a version, make version constraint from the version and use the comparator from the previous item and make comparator empty
1011+ # If it's a version with comparator, use split_req to get version and comparator to form constraint and make comparator empty
1012+ for constraint_item in constraint_items :
1013+ if not constraint_item :
1014+ continue
1015+ if "" .join ([comparator , constraint_item ]) in vrc .vers_by_native_comparators :
1016+ comparator = "" .join ([comparator , constraint_item ])
1017+ comparator = vrc .vers_by_native_comparators [comparator ]
1018+ continue
1019+ if comparator :
1020+ constraints .append (
1021+ VersionConstraint (comparator = comparator , version = vrc .version_class (constraint_item ))
1022+ )
1023+ else :
1024+ comparator , version_constraint = split_req (
1025+ constraint_item , vrc .vers_by_native_comparators
1026+ )
1027+ constraints .append (
1028+ VersionConstraint (
1029+ comparator = comparator , version = vrc .version_class (version_constraint )
10161030 )
1017- comparator = ""
1018- return vrc (constraints = constraints )
1031+ )
1032+ comparator = ""
1033+ return vrc (constraints = constraints )
10191034
10201035
10211036vers_by_github_native_comparators = {
0 commit comments