@@ -34,6 +34,28 @@ class InvalidVersion(ValueError):
3434 pass
3535
3636
37+ def is_valid_alpine_version (s ):
38+ """
39+ Return True is the string `s` is a valid Alpine version.
40+ We do not support yet version strings that start with
41+ non-significant zeros.
42+ For example:
43+ >>> is_valid_alpine_version("006")
44+ False
45+ >>> is_valid_alpine_version("1.2.3")
46+ True
47+ >>> is_valid_alpine_version("02-r1")
48+ False
49+ """
50+ left , _ , _ = s .partition ("." )
51+ # hanlde the suffix case
52+ left , _ , _ = left .partition ("-" )
53+ if not left .isdigit ():
54+ return True
55+ i = int (left )
56+ return str (i ) == left
57+
58+
3759@attr .s (frozen = True , order = False , hash = True )
3860class Version :
3961 """
@@ -299,3 +321,25 @@ def __lt__(self, other):
299321 if not isinstance (other , self .__class__ ):
300322 return NotImplemented
301323 return gentoo .vercmp (self .value , other .value ) == - 1
324+
325+
326+ @attr .s (frozen = True , order = False , eq = False , hash = True )
327+ class AlpineLinuxVersion (Version ):
328+ @classmethod
329+ def is_valid (cls , string ):
330+ return is_valid_alpine_version (string ) and gentoo .is_valid (string )
331+
332+ def __eq__ (self , other ):
333+ if not isinstance (other , self .__class__ ):
334+ return NotImplemented
335+ return gentoo .vercmp (self .value , other .value ) == 0
336+
337+ def __lt__ (self , other ):
338+ if not isinstance (other , self .__class__ ):
339+ return NotImplemented
340+ return gentoo .vercmp (self .value , other .value ) < 0
341+
342+ def __gt__ (self , other ):
343+ if not isinstance (other , self .__class__ ):
344+ return NotImplemented
345+ return gentoo .vercmp (self .value , other .value ) > 0
0 commit comments