Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARPY-1522 also remove EOL python versions #2189

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@
import org.sonar.plugins.python.api.PythonVersionUtils;
import org.sonar.python.checks.utils.PythonCheckVerifier;

import static org.assertj.core.api.Assertions.assertThat;

class PytzUsageCheckTest {
@Test
void test_38() {
ProjectPythonVersion.setCurrentVersions(EnumSet.of(PythonVersionUtils.Version.V_38));
var issues = PythonCheckVerifier.issues("src/test/resources/checks/pytzUsage.py", new PytzUsageCheck());
assertThat(issues)
.isEmpty();
}

@Test
void test_39_310_311_312() {
ProjectPythonVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_311;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_312;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_313;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_36;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_37;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_38;
import static org.sonar.plugins.python.api.PythonVersionUtils.Version.V_39;

public class PythonVersionUtils {

public enum Version {
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"),
Expand Down Expand Up @@ -78,27 +74,28 @@ public String toString() {
}
}

private static final Version MIN_SUPPORTED_VERSION = V_38;
public static final Version MAX_SUPPORTED_VERSION = V_313;

/**
* Note that versions between 3 and 3.6 are currently mapped to 3.6 because
* Note that versions between 3 and 3.8 are currently mapped to 3.8 because
* we don't take into account those version during typeshed symbols serialization
*/
private static final Map<String, Version> STRING_VERSION_MAP = Map.ofEntries(
Map.entry("3.0", V_36),
Map.entry("3.1", V_36),
Map.entry("3.2", V_36),
Map.entry("3.3", V_36),
Map.entry("3.4", V_36),
Map.entry("3.5", V_36),
Map.entry("3.6", V_36),
Map.entry("3.7", V_37),
Map.entry("3.0", MIN_SUPPORTED_VERSION),
Map.entry("3.1", MIN_SUPPORTED_VERSION),
Map.entry("3.2", MIN_SUPPORTED_VERSION),
Map.entry("3.3", MIN_SUPPORTED_VERSION),
Map.entry("3.4", MIN_SUPPORTED_VERSION),
Map.entry("3.5", MIN_SUPPORTED_VERSION),
Map.entry("3.6", MIN_SUPPORTED_VERSION),
Map.entry("3.7", MIN_SUPPORTED_VERSION),
Map.entry("3.8", V_38),
Map.entry("3.9", V_39),
Map.entry("3.10", V_310),
Map.entry("3.11", V_311),
Map.entry("3.12", V_312),
Map.entry("3.13", V_313));
private static final Version MIN_SUPPORTED_VERSION = V_36;
public static final Version MAX_SUPPORTED_VERSION = V_313;
private static final Logger LOG = LoggerFactory.getLogger(PythonVersionUtils.class);
public static final String PYTHON_VERSION_KEY = "sonar.python.version";

Expand Down Expand Up @@ -175,12 +172,6 @@ public static boolean areSourcePythonVersionsGreaterOrEqualThan(Set<Version> sou
.allMatch(version -> version.compare(required.major(), required.minor()) >= 0);
}

/**
* @return the set of versions which are supported but not serialized due to SONARPY-1522
*/
public static Set<Version> getNotSerializedVersions() {
return EnumSet.of(V_312, V_313);
}

private static void logErrorMessage(String propertyValue) {
LOG.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sonar.plugins.python.api.PythonVersionUtils;
import org.sonar.python.index.AmbiguousDescriptor;
import org.sonar.python.index.Descriptor;

Expand Down Expand Up @@ -50,13 +49,6 @@ static boolean isValidForPythonVersion(List<String> validForPythonVersions, Set<
if (validForPythonVersions.isEmpty()) {
return true;
}
// TODO: SONARPY-1522 - remove this workaround when we will have all the stubs for Python 3.12.
Set<String> notSerializedVersions =
PythonVersionUtils.getNotSerializedVersions().stream().map(PythonVersionUtils.Version::serializedValue).collect(Collectors.toSet());
if (notSerializedVersions.containsAll(supportedPythonVersions)
&& validForPythonVersions.contains(PythonVersionUtils.Version.V_311.serializedValue())) {
return true;
}
HashSet<String> intersection = new HashSet<>(validForPythonVersions);
intersection.retainAll(supportedPythonVersions);
return !intersection.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ public static boolean isValidForProjectPythonVersion(List<String> validForPython
if (validForPythonVersions.isEmpty()) {
return true;
}
// TODO: SONARPY-1522 - remove this workaround when we will have all the stubs for Python 3.12.
Set<String> notSerializedVersions = PythonVersionUtils.getNotSerializedVersions().stream().map(PythonVersionUtils.Version::serializedValue).collect(Collectors.toSet());
if (notSerializedVersions.containsAll(supportedPythonVersions)
&& validForPythonVersions.contains(PythonVersionUtils.Version.V_311.serializedValue())) {
return true;
if(supportedPythonVersions == null) {
throw new IllegalStateException("supportedPythonVersion is uninitialized. Call builtinSymbols() first");
}
HashSet<String> intersection = new HashSet<>(validForPythonVersions);
intersection.retainAll(supportedPythonVersions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


__future__�
_Feature__future__._Feature"builtins.object*�
__future__�
_Feature__future__._Feature"builtins.object*�
__init____future__._Feature.__init__"
None*4
self*
Expand All @@ -25,7 +25,7 @@ GTuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]
builtins.int" builtins.int"__future__._VersionInfo
None*/
compiler_flag
builtins.int" builtins.intz36z37z38z39z310z311*�
builtins.int" builtins.intz38z39z310z311z312z313*�
getOptionalRelease&__future__._Feature.getOptionalRelease"�
RTypeAlias[Tuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]]�
GTuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]
Expand All @@ -35,7 +35,7 @@ GTuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]
builtins.str" builtins.str
builtins.int" builtins.int"__future__._VersionInfo*4
self*
__future__._Feature"__future__._Featurez36z37z38z39z310z311*�
__future__._Feature"__future__._Featurez38z39z310z311z312z313*�
getMandatoryRelease'__future__._Feature.getMandatoryRelease"�
^Union[TypeAlias[Tuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]],None]�
RTypeAlias[Tuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]]�
Expand All @@ -47,37 +47,37 @@ GTuple[builtins.int,builtins.int,builtins.int,builtins.str,builtins.int]
builtins.int" builtins.int"__future__._VersionInfo
None*4
self*
__future__._Feature"__future__._Featurez36z37z38z39z310z311j36j37j38j39j310j311rj
__future__._Feature"__future__._Featurez38z39z310z311z312z313j38j39j310j311j312j313rl
compiler_flag!__future__._Feature.compiler_flag
builtins.int" builtins.int*36*37*38*39*310*311*�
builtins.int" builtins.int*38*39*310*311*312*313*�
__annotations____future__.__annotations__W
builtins.dict[builtins.str,Any]
builtins.str" builtins.str
Any"builtins.dict*36*37*38*39*310*311*s
Any"builtins.dict*38*39*310*311*312*313*u
absolute_import__future__.absolute_import*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*e
__future__._Feature"__future__._Feature*38*39*310*311*312*313*g
division__future__.division*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*i
__future__._Feature"__future__._Feature*38*39*310*311*312*313*k

generators__future__.generators*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*o
__future__._Feature"__future__._Feature*38*39*310*311*312*313*q
nested_scopes__future__.nested_scopes*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*q
__future__._Feature"__future__._Feature*38*39*310*311*312*313*s
print_function__future__.print_function*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*u
__future__._Feature"__future__._Feature*38*39*310*311*312*313*w
unicode_literals__future__.unicode_literals*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*q
__future__._Feature"__future__._Feature*38*39*310*311*312*313*s
with_statement__future__.with_statement*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*q
__future__._Feature"__future__._Feature*38*39*310*311*312*313*s
barry_as_FLUFL__future__.barry_as_FLUFL*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*q
__future__._Feature"__future__._Feature*38*39*310*311*312*313*s
generator_stop__future__.generator_stop*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*k
__future__._Feature"__future__._Feature*38*39*310*311*312*313*m
annotations__future__.annotations*
__future__._Feature"__future__._Feature*36*37*38*39*310*311*�
__future__._Feature"__future__._Feature*38*39*310*311*312*313*�
all_feature_names__future__.all_feature_namesJ
builtins.list[builtins.str]
builtins.str" builtins.str"builtins.list*36*37*38*39*310*311*�
builtins.str" builtins.str"builtins.list*38*39*310*311*312*313*�
__all____future__.__all__J
builtins.list[builtins.str]
builtins.str" builtins.str"builtins.list*36*37*38*39*310*311
builtins.str" builtins.str"builtins.list*38*39*310*311*312*313
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

__main__f
__main__h
__getattr____main__.__getattr__"
Any*
builtins.str" builtins.strz36z37z38z39z310z311*�
builtins.str" builtins.strz38z39z310z311z312z313*�
__annotations____main__.__annotations__W
builtins.dict[builtins.str,Any]
builtins.str" builtins.str
Any"builtins.dict*36*37*38*39*310*311
Any"builtins.dict*38*39*310*311*312*313
Expand Down
Loading