Skip to content

Commit 28eb718

Browse files
committed
Add alpine support in univers
Currently univers don't have a VersionClass for alpine linux, so add a version class for alpine linux and use same vercmp method that has been used by gentoo, avoid cases for now which have a leading 0 in them. Verify the current implementation of vercmp with the test data from here https://git.alpinelinux.org/apk-tools/tree/tests/version.data addABOUT file and license for same Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 2186416 commit 28eb718

10 files changed

Lines changed: 822 additions & 10 deletions

src/univers/debian.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ def compare_strings(version1, version2):
256256
logger.debug("Comparing non-digit prefixes %r and %r ..", p1, p2)
257257
for c1, c2 in zip_longest(p1, p2, fillvalue=""):
258258
logger.debug(
259-
"Performing lexical comparison between characters %r and %r ..", c1, c2
259+
"Performing lexical comparison between characters %r and %r ..",
260+
c1,
261+
c2,
260262
)
261263
o1 = mapping.get(c1)
262264
o2 = mapping.get(c2)

src/univers/version_range.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ class EbuildVersionRange(VersionRange):
721721
version_class = versions.GentooVersion
722722

723723

724+
class AlpineLinuxVersionRange(VersionRange):
725+
scheme = "alpinelinux"
726+
version_class = versions.AlpineLinuxVersion
727+
728+
724729
class ArchLinuxVersionRange(VersionRange):
725730
scheme = "archlinux"
726731
version_class = versions.ArchLinuxVersion

src/univers/versions.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class InvalidVersion(ValueError):
3434
pass
3535

3636

37+
def valid_alpine_version(s):
38+
left, _, _ = s.partition(".")
39+
if not left.isdigit():
40+
return True
41+
i = int(left)
42+
return str(i) == left
43+
44+
3745
@attr.s(frozen=True, order=False, hash=True)
3846
class Version:
3947
"""
@@ -299,3 +307,25 @@ def __lt__(self, other):
299307
if not isinstance(other, self.__class__):
300308
return NotImplemented
301309
return gentoo.vercmp(self.value, other.value) == -1
310+
311+
312+
@attr.s(frozen=True, order=False, eq=False, hash=True)
313+
class AlpineLinuxVersion(Version):
314+
@classmethod
315+
def is_valid(cls, string):
316+
return valid_alpine_version(string) and gentoo.is_valid(string)
317+
318+
def __eq__(self, other):
319+
if not isinstance(other, self.__class__):
320+
return NotImplemented
321+
return gentoo.vercmp(self.value, other.value) == 0
322+
323+
def __lt__(self, other):
324+
if not isinstance(other, self.__class__):
325+
return NotImplemented
326+
return gentoo.vercmp(self.value, other.value) < 0
327+
328+
def __gt__(self, other):
329+
if not isinstance(other, self.__class__):
330+
return NotImplemented
331+
return gentoo.vercmp(self.value, other.value) > 0

0 commit comments

Comments
 (0)