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,100 @@ 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
+ self ._data = data
54
+
55
+ def __str__ (self ):
56
+ """
57
+ Version as string.
58
+ """
59
+ _ = f"{ self .major } "
60
+ if self .minor is not None :
61
+ _ += f".{ self .minor } "
62
+ if self .micro is not None :
63
+ _ += f".{ self .micro } "
64
+ # XXX What if minor was None but micro was an int.
65
+ return _
66
+
67
+ @staticmethod
68
+ def parse_string (data ):
69
+ """
70
+ Parse a version string into major, minor, and micro integers.
71
+ """
72
+ parts = data .split ("." )
73
+ if len (parts ) == 1 :
74
+ return int (parts [0 ]), None , None
75
+ elif len (parts ) == 2 :
76
+ return int (parts [0 ]), int (parts [1 ]), None
77
+ elif len (parts ) == 3 :
78
+ return int (parts [0 ]), int (parts [1 ]), int (parts [2 ])
79
+ else :
80
+ raise RuntimeError ("Too many parts to parse" )
81
+
82
+ def __eq__ (self , other ):
83
+ """
84
+ Equality comparrison.
85
+ """
86
+ mymajor = 0 if self .major is None else self .major
87
+ myminor = 0 if self .minor is None else self .minor
88
+ mymicro = 0 if self .micro is None else self .micro
89
+ major = 0 if other .major is None else other .major
90
+ minor = 0 if other .minor is None else other .minor
91
+ micro = 0 if other .micro is None else other .micro
92
+ return mymajor == major and myminor == minor and mymicro == micro
93
+
94
+ def __lt__ (self , other ):
95
+ """
96
+ Less than comparrison.
97
+ """
98
+ mymajor = 0 if self .major is None else self .major
99
+ myminor = 0 if self .minor is None else self .minor
100
+ mymicro = 0 if self .micro is None else self .micro
101
+ major = 0 if other .major is None else other .major
102
+ minor = 0 if other .minor is None else other .minor
103
+ micro = 0 if other .micro is None else other .micro
104
+ if mymajor < major :
105
+ return True
106
+ elif mymajor == major :
107
+ if myminor < minor :
108
+ return True
109
+ if myminor == minor and mymicro < micro :
110
+ return True
111
+ return False
112
+
113
+ def __le__ (self , other ):
114
+ """
115
+ Less than or equal to comparrison.
116
+ """
117
+ mymajor = 0 if self .major is None else self .major
118
+ myminor = 0 if self .minor is None else self .minor
119
+ mymicro = 0 if self .micro is None else self .micro
120
+ major = 0 if other .major is None else other .major
121
+ minor = 0 if other .minor is None else other .minor
122
+ micro = 0 if other .micro is None else other .micro
123
+ if mymajor <= major :
124
+ if myminor <= minor :
125
+ if mymicro <= micro :
126
+ return True
127
+ return False
128
+
129
+ def __gt__ (self , other ):
130
+ """
131
+ Greater than comparrison.
132
+ """
133
+ return not self .__le__ (other )
134
+
135
+ def __ge__ (self , other ):
136
+ """
137
+ Greater than or equal to comparrison.
138
+ """
139
+ return not self .__lt__ (other )
45
140
46
141
47
142
def _release_urls (version , gzip = False ):
0 commit comments