27
27
import org .sonar .api .utils .log .Logger ;
28
28
import org .sonar .api .utils .log .Loggers ;
29
29
30
- import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_27 ;
31
30
import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_310 ;
32
- import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_35 ;
31
+ import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_311 ;
33
32
import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_36 ;
34
33
import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_37 ;
35
34
import static org .sonar .plugins .python .api .PythonVersionUtils .Version .V_38 ;
38
37
public class PythonVersionUtils {
39
38
40
39
public enum Version {
41
- V_27 (2 , 7 , "27" ),
42
- V_35 (3 , 5 , "35" ),
43
40
V_36 (3 , 6 , "36" ),
44
41
V_37 (3 , 7 , "37" ),
45
42
V_38 (3 , 8 , "38" ),
46
43
V_39 (3 , 9 , "39" ),
47
- V_310 (3 , 10 , "310" );
44
+ V_310 (3 , 10 , "310" ),
45
+ V_311 (3 , 11 , "311" );
48
46
49
47
private final int major ;
50
48
private final int minor ;
@@ -82,28 +80,25 @@ public String toString() {
82
80
}
83
81
84
82
/**
85
- * Note that versions between 3 and 3.5 are currently mapped to 3.5 because
83
+ * Note that versions between 3 and 3.6 are currently mapped to 3.6 because
86
84
* we don't take into account those version during typeshed symbols serialization
87
85
*/
88
- private static final Map <String , Version > STRING_VERSION_MAP = new HashMap <>();
89
- static {
90
- STRING_VERSION_MAP .put ("2" , V_27 );
91
- STRING_VERSION_MAP .put ("2.7" , V_27 );
92
- STRING_VERSION_MAP .put ("3" , V_35 );
93
- STRING_VERSION_MAP .put ("3.0" , V_35 );
94
- STRING_VERSION_MAP .put ("3.1" , V_35 );
95
- STRING_VERSION_MAP .put ("3.2" , V_35 );
96
- STRING_VERSION_MAP .put ("3.3" , V_35 );
97
- STRING_VERSION_MAP .put ("3.4" , V_35 );
98
- STRING_VERSION_MAP .put ("3.5" , V_35 );
99
- STRING_VERSION_MAP .put ("3.6" , V_36 );
100
- STRING_VERSION_MAP .put ("3.7" , V_37 );
101
- STRING_VERSION_MAP .put ("3.8" , V_38 );
102
- STRING_VERSION_MAP .put ("3.9" , V_39 );
103
- STRING_VERSION_MAP .put ("3.10" , V_310 );
104
- }
105
- private static final Version MIN_SUPPORTED_VERSION = V_27 ;
106
- private static final Version MAX_SUPPORTED_VERSION = V_310 ;
86
+ private static final Map <String , Version > STRING_VERSION_MAP = Map .ofEntries (
87
+ Map .entry ("3.0" , V_36 ),
88
+ Map .entry ("3.1" , V_36 ),
89
+ Map .entry ("3.2" , V_36 ),
90
+ Map .entry ("3.3" , V_36 ),
91
+ Map .entry ("3.4" , V_36 ),
92
+ Map .entry ("3.5" , V_36 ),
93
+ Map .entry ("3.6" , V_36 ),
94
+ Map .entry ("3.7" , V_37 ),
95
+ Map .entry ("3.8" , V_38 ),
96
+ Map .entry ("3.9" , V_39 ),
97
+ Map .entry ("3.10" , V_310 ),
98
+ Map .entry ("3.11" , V_311 )
99
+ );
100
+ private static final Version MIN_SUPPORTED_VERSION = V_36 ;
101
+ private static final Version MAX_SUPPORTED_VERSION = V_311 ;
107
102
private static final Logger LOG = Loggers .get (PythonVersionUtils .class );
108
103
public static final String PYTHON_VERSION_KEY = "sonar.python.version" ;
109
104
@@ -118,6 +113,10 @@ public static Set<Version> fromString(String propertyValue) {
118
113
Set <Version > pythonVersions = EnumSet .noneOf (Version .class );
119
114
for (String versionValue : versions ) {
120
115
versionValue = versionValue .trim ();
116
+ if ("3" .equals (versionValue )) {
117
+ // Only 3.x stubs are supported
118
+ return allVersions ();
119
+ }
121
120
Version version = STRING_VERSION_MAP .get (versionValue );
122
121
if (version != null ) {
123
122
pythonVersions .add (version );
@@ -146,6 +145,10 @@ private static boolean guessPythonVersion(Set<Version> pythonVersions, String ve
146
145
logWarningGuessVersion (versionValue , guessedVersion );
147
146
return true ;
148
147
}
148
+ if (major < 3 ) {
149
+ logWarningPython2 (versionValue );
150
+ return false ;
151
+ }
149
152
if (MIN_SUPPORTED_VERSION .compare (major , minor ) > 0 ) {
150
153
pythonVersions .add (MIN_SUPPORTED_VERSION );
151
154
logWarningGuessVersion (versionValue , MIN_SUPPORTED_VERSION );
@@ -172,4 +175,9 @@ private static void logWarningGuessVersion(String propertyValue, Version guessed
172
175
String prefix = "No explicit support for version %s. Python version has been set to %s." ;
173
176
LOG .warn (String .format (Locale .ROOT , prefix , propertyValue , guessedVersion ));
174
177
}
178
+
179
+ private static void logWarningPython2 (String propertyValue ) {
180
+ String prefix = "No explicit support for version %s. Support for Python versions prior to 3 is deprecated." ;
181
+ LOG .warn (String .format (Locale .ROOT , prefix , propertyValue ));
182
+ }
175
183
}
0 commit comments