3
3
"""
4
4
Versions utility.
5
5
"""
6
- try :
7
- from packaging .version import Version
8
- except ImportError :
9
- raise RuntimeError (
10
- "Required dependencies not found. Please pip install relenv[pyversions]"
11
- )
12
-
6
+ # try:
7
+ # from packaging.version import Version
8
+ # except ImportError:
9
+ # raise RuntimeError(
10
+ # "Required dependencies not found. Please pip install relenv[pyversions]"
11
+ # )
12
+ #
13
13
14
14
import hashlib
15
15
import json
31
31
"pgp.mit.edu" ,
32
32
]
33
33
34
+ ARCHIVE = "https://www.python.org/ftp/python/{version}/Python-{version}.{ext}"
35
+
34
36
35
37
def _ref_version (x ):
36
38
_ = x .split ("Python " , 1 )[1 ].split ("<" , 1 )[0 ]
@@ -41,7 +43,87 @@ def _ref_path(x):
41
43
return x .split ('href="' )[1 ].split ('"' )[0 ]
42
44
43
45
44
- ARCHIVE = "https://www.python.org/ftp/python/{version}/Python-{version}.{ext}"
46
+ class Version :
47
+ """
48
+ Version comparrisons.
49
+ """
50
+
51
+ def __init__ (self , data ):
52
+ self .major , self .minor , self .micro = self .parse_string (data )
53
+
54
+ @staticmethod
55
+ def parse_string (data ):
56
+ """
57
+ Parse a version string into major, minor, and micro integers.
58
+ """
59
+ parts = data .split ("." )
60
+ if len (parts ) == 1 :
61
+ return int (parts [0 ]), None , None
62
+ elif len (parts ) == 2 :
63
+ return int (parts [0 ]), int (parts [1 ]), None
64
+ elif len (parts ) == 3 :
65
+ return int (parts [0 ]), int (parts [1 ]), int (parts [2 ])
66
+ else :
67
+ raise RuntimeError ("Too many parts to parse" )
68
+
69
+ def __eq__ (self , other ):
70
+ """
71
+ Equality comparrison.
72
+ """
73
+ mymajor = 0 if self .major is None else self .major
74
+ myminor = 0 if self .minor is None else self .minor
75
+ mymicro = 0 if self .micro is None else self .micro
76
+ major = 0 if other .major is None else other .major
77
+ minor = 0 if other .minor is None else other .minor
78
+ micro = 0 if other .micro is None else other .micro
79
+ return mymajor == major and myminor == minor and mymicro == micro
80
+
81
+ def __lt__ (self , other ):
82
+ """
83
+ Less than comparrison.
84
+ """
85
+ mymajor = 0 if self .major is None else self .major
86
+ myminor = 0 if self .minor is None else self .minor
87
+ mymicro = 0 if self .micro is None else self .micro
88
+ major = 0 if other .major is None else other .major
89
+ minor = 0 if other .minor is None else other .minor
90
+ micro = 0 if other .micro is None else other .micro
91
+ if mymajor < major :
92
+ return True
93
+ elif mymajor == major :
94
+ if myminor < minor :
95
+ return True
96
+ if myminor == minor and mymicro < micro :
97
+ return True
98
+ return False
99
+
100
+ def __le__ (self , other ):
101
+ """
102
+ Less than or equal to comparrison.
103
+ """
104
+ mymajor = 0 if self .major is None else self .major
105
+ myminor = 0 if self .minor is None else self .minor
106
+ mymicro = 0 if self .micro is None else self .micro
107
+ major = 0 if other .major is None else other .major
108
+ minor = 0 if other .minor is None else other .minor
109
+ micro = 0 if other .micro is None else other .micro
110
+ if mymajor <= major :
111
+ if myminor <= minor :
112
+ if mymicro <= micro :
113
+ return True
114
+ return False
115
+
116
+ def __gt__ (self , other ):
117
+ """
118
+ Greater than comparrison.
119
+ """
120
+ return not self .__le__ (other )
121
+
122
+ def __ge__ (self , other ):
123
+ """
124
+ Greater than or equal to comparrison.
125
+ """
126
+ return not self .__lt__ (other )
45
127
46
128
47
129
def _release_urls (version , gzip = False ):
0 commit comments