Skip to content

Commit 9a460be

Browse files
committed
Add support for gitlab in pypi, npm, gem version ranges
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 5a514f0 commit 9a460be

5 files changed

Lines changed: 5913 additions & 0 deletions

File tree

src/univers/version_range.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -974,6 +975,51 @@ def from_native(cls, string):
974975
return cls(constraints=constraints)
975976

976977

978+
class GitLabVersionRange(VersionRange):
979+
@classmethod
980+
def from_gitlab_native(cls, scheme, string):
981+
vrc = RANGE_CLASS_BY_SCHEMES[scheme]
982+
constraint_items = []
983+
constraints = []
984+
split = " "
985+
if scheme == "pypi":
986+
split = ","
987+
pipe_separated_constraints = string.split("||")
988+
for pipe_separated_constraint in pipe_separated_constraints:
989+
space_seperated_constraints = pipe_separated_constraint.split(split)
990+
constraint_items.extend(space_seperated_constraints)
991+
comparator = ""
992+
# A constraint item can be a comparator or a version or a version with comparator
993+
# If it's empty continue
994+
# If it's in `vers_by_native_comparators`, append it with the comparator and continue
995+
# If it's a version, make version constraint from the version and use the comparator from the previous item and make comparator empty
996+
# If it's a version with comparator, use split_req to get version and comparator to form constraint and make comparator empty
997+
for constraint_item in constraint_items:
998+
if not constraint_item:
999+
continue
1000+
if "".join([comparator, constraint_item]) in vrc.vers_by_native_comparators:
1001+
comparator = "".join([comparator, constraint_item])
1002+
comparator = vrc.vers_by_native_comparators[comparator]
1003+
continue
1004+
if comparator:
1005+
constraints.append(
1006+
VersionConstraint(
1007+
comparator=comparator, version=vrc.version_class(constraint_item)
1008+
)
1009+
)
1010+
else:
1011+
comparator, version_constraint = split_req(
1012+
constraint_item, vrc.vers_by_native_comparators
1013+
)
1014+
constraints.append(
1015+
VersionConstraint(
1016+
comparator=comparator, version=vrc.version_class(version_constraint)
1017+
)
1018+
)
1019+
comparator = ""
1020+
return vrc(constraints=constraints)
1021+
1022+
9771023
vers_by_github_native_comparators = {
9781024
"=": "=",
9791025
"!=": "!=",

0 commit comments

Comments
 (0)