-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Pylint checks should be way faster now #10207
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering if we can first run pylint for main sources and then, just add additional disables to
pylintrc
? Not sure if this will be simplerUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what we did before and that was a pain. It took much more time than this one.
This is a huge optimization, that's why I did it.
The problem is that when you run pylint for tests, it also pulls in all the tested code which means that basically a lot of the main airflow code was parsed and processed twice - once in the "pylint main" and once in the "pylint tests". This code was not verified by Pylint but it was parsed and analyzed so that the test code could be pylint-checked so it's not a full duplication, but I think the savings are significant
Some random stats:
Before the change:
pylint main: 6:20s
pylint tests: 3:59s
Tota: 10m 20s
After the change:
combined pylint: 8:20s
So we save 20% (2 minutes) of elapsed time by doing this.