forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pylint checks should be way faster now (apache#10207)
* Pylint checks should be way faster now Instead of running separate pylint checks for tests and main source we are running a single check now. This is possible thanks to a nice hack - we have pylint plugin that injects the right "# pylint: disable=" comment for all test files while reading the file content by astroid (just before tokenization) Thanks to that we can also separate out pylint checks to a separate job in CI - this way all pylint checks will be run in parallel to all other checks effectively halfing the time needed to get the static check feedback and potentially cancelling other jobs much faster. * fixup! Pylint checks should be way faster now
- Loading branch information
Showing
15 changed files
with
116 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
from astroid import MANAGER, scoped_nodes | ||
from pylint.lint import PyLinter | ||
|
||
DISABLED_CHECKS_FOR_TESTS = \ | ||
"missing-docstring, no-self-use, too-many-public-methods, protected-access, do-not-use-asserts" | ||
|
||
|
||
def register(_: PyLinter): | ||
""" | ||
Skip registering any plugin. This is not a real plugin - we only need it to register transform before | ||
running pylint. | ||
:param _: | ||
:return: | ||
""" | ||
|
||
|
||
def transform(mod): | ||
""" | ||
It's a small hack but one that gives us a lot of speedup in pylint tests. We are replacing the first | ||
line of the file with pylint-disable (or update existing one) when file name start with `test_` or | ||
(for providers) when it is the full path of the package (both cases occur in pylint) | ||
:param mod: astroid module | ||
:return: None | ||
""" | ||
if mod.name.startswith("test_") or \ | ||
mod.name.startswith("tests.") or \ | ||
mod.name.startswith("kubernetes_tests."): | ||
decoded_lines = mod.stream().read().decode("utf-8").split("\n") | ||
if decoded_lines[0].startswith("# pylint: disable="): | ||
decoded_lines[0] = decoded_lines[0] + " " + DISABLED_CHECKS_FOR_TESTS | ||
elif decoded_lines[0].startswith("#") or decoded_lines[0].strip() == "": | ||
decoded_lines[0] = "# pylint: disable=" + DISABLED_CHECKS_FOR_TESTS | ||
else: | ||
raise Exception(f"The first line of module {mod.name} is not a comment or empty. " | ||
f"Please make sure it is!") | ||
# pylint will read from `.file_bytes` attribute later when tokenization | ||
mod.file_bytes = "\n".join(decoded_lines).encode("utf-8") | ||
|
||
|
||
MANAGER.register_transform(scoped_nodes.Module, transform) |
Oops, something went wrong.