-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Make our custom pylint plugin use the AST #5332
Make our custom pylint plugin use the AST #5332
Conversation
If this change offers any speedups, the speedups are negligible. CI master - https://github.com/StackStorm/st2/actions/runs/1140506567 CI unrelated PR - https://github.com/StackStorm/st2/actions/runs/1140762169 CI with pylint AST changes (this PR) - https://github.com/StackStorm/st2/actions/runs/1140785614 |
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 guess LGTM if it works although I preferred older much simpler and shorter solution :)
But yeah in general I also agree on the import time side affects not being good (although in this case it was bit less of an issue since pylint always ran as part of a separate isolated process).
Could you please just gist an example of the error when is displayed if some of the code violates this pylint rule?
I have been experimenting with running all of our linting tools via Here are the conversations from when I was debugging the pylint issues I was hitting.
Here's a gist of the pants + pylint output with lots of weird import errors. https://gist.github.com/cognifloyd/f428a423a07e1e859d4e2625c0cd66f1#file-pants-lint-st2api A shorter/trimmed version of that error:
Some of the errors in that gist were caused by: pylint-dev/pylint#2095 (where in pylint's cache So, this PR makes our testing infrastructure more flexible, by allowing people to run pylint on more of our code and in more contexts. edit: I don't have any tracebacks/gists from the times I ran into an eventlet triggered hang, and I'm not sure if I encountered it while running pylint or something else. I debugged all of this a couple months ago. |
537578d
to
9f0fdc7
Compare
Rebased on master. @Kami Is anything left before we can merge this? Could you review (and hopefully approve)? |
@cognifloyd How do you run pylint manually? I have not run into issue or have seen the errors you posted above. The changes here looks more complex than before. |
Importing code that we are linting is not nice. It breaks the promise of pylint because it is no longer static code analysis, it is reflection. I have been experimenting running pylint via another program called pants, because it promises to have aggressive caching of results to speed things up. It understands python imports, and so it can track and see that if you change a file b and file a imports file b, then it needs to rerun lint and test steps on both file a and file b, not just the one file you changed. That could really speed up PR CI. Plus, I had one company suggest they would give StackStorm an open source plan to use their remote execution services which would allow us to share cached results between CI and local, so that the tests are that much faster both in CI and locally. However, because our plugin is using |
I guess I failed in my goal of justifying this without referencing |
OK. I'm adding a bunch of comments to this code to explain how it works and what it is doing. |
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 looks good to me and I think it's a great improvement. But I'd love to see more reviews by other maintainers.
I added tests for the pylint plugin. |
# Create a "property = node" assign node | ||
assign_node = nodes.Assign(parent=cls) | ||
assign_name_node = nodes.AssignName(property_name, parent=assign_node) | ||
assign_node.postinit(targets=[assign_name_node], value=node) | ||
|
||
# Finally, add the property node as an attribute on the class. | ||
cls.locals[property_name] = [assign_name_node] |
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.
In writing tests, I realized that we were modifying the AST incorrectly in the original plugin. This is the correct way to do it.
pylint plugins are supposed to inspect code without importing it to avoid side effects like importing eventlet.
In some of my manual pylint runs, I ran into a variety of really odd errors and hangs that were ultimately caused by importing the st2 modules from within the pylint plugin.
So, this PR modifies the plugin to use the astroid AST instead of using
__import__
.This is a draft while I compare run times with master branch. I'm curious if this will speed things up at all.__import__()