38
38
public class PythonVersionUtils {
39
39
40
40
public enum Version {
41
- V_27 (2.7 , "27" ), V_35 (3.5 , "35" ), V_36 (3.6 , "36" ), V_37 (3.7 , "37" ), V_38 (3.8 , "38" ), V_39 (3.9 , "39" ), V_310 (3.10 , "310" );
41
+ V_27 (2 , 7 , "27" ),
42
+ V_35 (3 , 5 , "35" ),
43
+ V_36 (3 , 6 , "36" ),
44
+ V_37 (3 , 7 , "37" ),
45
+ V_38 (3 , 8 , "38" ),
46
+ V_39 (3 , 9 , "39" ),
47
+ V_310 (3 , 10 , "310" );
42
48
43
- private final double value ;
49
+ private final int major ;
50
+ private final int minor ;
44
51
private final String serializedValue ;
45
52
46
- Version (double value , String serializedValue ) {
47
- this .value = value ;
53
+ Version (int major , int minor , String serializedValue ) {
54
+ this .major = major ;
55
+ this .minor = minor ;
48
56
this .serializedValue = serializedValue ;
49
57
}
50
58
51
- public double value () {
52
- return value ;
59
+ public int major () {
60
+ return major ;
61
+ }
62
+
63
+ public int minor () {
64
+ return minor ;
53
65
}
54
66
55
67
public String serializedValue () {
56
68
return serializedValue ;
57
69
}
70
+
71
+ public int compare (int major , int minor ) {
72
+ if (major () == major ) {
73
+ return Integer .compare (minor (), minor );
74
+ }
75
+ return Integer .compare (major (), major );
76
+ }
77
+
78
+ @ Override
79
+ public String toString () {
80
+ return major + "." + minor ;
81
+ }
58
82
}
59
83
60
84
/**
@@ -112,12 +136,22 @@ public static Set<Version> allVersions() {
112
136
}
113
137
114
138
private static boolean guessPythonVersion (Set <Version > pythonVersions , String versionValue ) {
139
+ String [] version = versionValue .split ("\\ ." );
115
140
try {
116
- double parsedVersion = Double .parseDouble (versionValue );
117
- if (parsedVersion < MIN_SUPPORTED_VERSION .value ()) {
141
+ int major = Integer .parseInt (version [0 ]);
142
+ int minor = version .length > 1 ? Integer .parseInt (version [1 ]) : 0 ;
143
+ Version guessedVersion = STRING_VERSION_MAP .get (major + "." + minor );
144
+ if (guessedVersion != null ) {
145
+ pythonVersions .add (guessedVersion );
146
+ logWarningGuessVersion (versionValue , guessedVersion );
147
+ return true ;
148
+ }
149
+ if (MIN_SUPPORTED_VERSION .compare (major , minor ) > 0 ) {
118
150
pythonVersions .add (MIN_SUPPORTED_VERSION );
119
- } else if (parsedVersion > MAX_SUPPORTED_VERSION .value ()) {
151
+ logWarningGuessVersion (versionValue , MIN_SUPPORTED_VERSION );
152
+ } else if (MAX_SUPPORTED_VERSION .compare (major , minor ) < 0 ) {
120
153
pythonVersions .add (MAX_SUPPORTED_VERSION );
154
+ logWarningGuessVersion (versionValue , MAX_SUPPORTED_VERSION );
121
155
} else {
122
156
logErrorMessage (versionValue );
123
157
return false ;
@@ -133,4 +167,9 @@ private static void logErrorMessage(String propertyValue) {
133
167
String prefix = "Error while parsing value of parameter '%s' (%s). Versions must be specified as MAJOR_VERSION.MIN.VERSION (e.g. \" 3.7, 3.8\" )" ;
134
168
LOG .warn (String .format (Locale .ROOT , prefix , PYTHON_VERSION_KEY , propertyValue ));
135
169
}
170
+
171
+ private static void logWarningGuessVersion (String propertyValue , Version guessedVersion ) {
172
+ String prefix = "No explicit support for version %s. Python version has been set to %s." ;
173
+ LOG .warn (String .format (Locale .ROOT , prefix , propertyValue , guessedVersion ));
174
+ }
136
175
}
0 commit comments