PY-55421 PY-63374 Update the bundled pycodestyle.py to 2.11.0

We now have to bundle three different versions of the script for all supported versions
of Python: 2.8.0 for Python 2.7, 2.9.0 for Python 3.6 and 3.7, and 2.11.0 for Python 3.8+.

GitOrigin-RevId: afed7339c5d7c4ca66b236e783f250b749430127
This commit is contained in:
Mikhail Golubev
2023-10-06 20:48:56 +00:00
committed by intellij-monorepo-bot
parent 484fb81597
commit 7f7037cbd1
5 changed files with 5833 additions and 420 deletions
+2732
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Regular → Executable
+264 -415
View File
File diff suppressed because it is too large Load Diff
@@ -72,7 +72,12 @@ public enum PythonHelper implements HelperPackage {
EXTRA_SYSPATH("extra_syspath.py"),
SYSPATH("syspath.py"),
// Compatible with 3.8+
PYCODESTYLE("pycodestyle.py"),
// Compatible with 3.6+
PYCODESTYLE_2_10_0("pycodestyle-2.10.0.py"),
// Compatible with 2.7 and 3.5+
PYCODESTYLE_2_8_0("pycodestyle-2.8.0.py"),
REST_RUNNER("rest_runners/rst2smth.py"),
@@ -106,15 +106,22 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
public static class State {
private final String interpreterPath;
private final LanguageLevel interpreterVersion;
private final String fileText;
private final HighlightDisplayLevel level;
private final List<String> ignoredErrors;
private final int margin;
private final boolean hangClosingBrackets;
public State(String interpreterPath, String fileText, HighlightDisplayLevel level,
List<String> ignoredErrors, int margin, boolean hangClosingBrackets) {
public State(String interpreterPath,
LanguageLevel interpreterVersion,
String fileText,
HighlightDisplayLevel level,
List<String> ignoredErrors,
int margin,
boolean hangClosingBrackets) {
this.interpreterPath = interpreterPath;
this.interpreterVersion = interpreterVersion;
this.fileText = fileText;
this.level = level;
this.ignoredErrors = ignoredErrors;
@@ -184,8 +191,13 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
ignoredErrors.add("E261"); // At least two spaces before inline comment
}
return new State(homePath, file.getText(), profile.getErrorLevel(key, file),
ignoredErrors, commonSettings.getRightMargin(PythonLanguage.getInstance()), customSettings.HANG_CLOSING_BRACKETS);
return new State(homePath,
LanguageLevel.forElement(file),
file.getText(),
profile.getErrorLevel(key, file),
ignoredErrors,
commonSettings.getRightMargin(PythonLanguage.getInstance()),
customSettings.HANG_CLOSING_BRACKETS);
}
private static void reportMissingInterpreter() {
@@ -212,7 +224,17 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
options.add("--max-line-length=" + collectedInfo.margin);
options.add("-");
GeneralCommandLine cmd = PythonHelper.PYCODESTYLE.newCommandLine(collectedInfo.interpreterPath, options);
PythonHelper pycodestyleScript;
if (collectedInfo.interpreterVersion.isOlderThan(LanguageLevel.PYTHON36)) {
pycodestyleScript = PythonHelper.PYCODESTYLE_2_8_0;
}
else if (collectedInfo.interpreterVersion.isOlderThan(LanguageLevel.PYTHON38)) {
pycodestyleScript = PythonHelper.PYCODESTYLE_2_10_0;
}
else {
pycodestyleScript = PythonHelper.PYCODESTYLE;
}
GeneralCommandLine cmd = pycodestyleScript.newCommandLine(collectedInfo.interpreterPath, options);
ProcessOutput output = PySdkUtil.getProcessOutput(cmd, new File(collectedInfo.interpreterPath).getParent(),
ImmutableMap.of("PYTHONBUFFERED", "1"),