Are there any astroid / pylint wizards here? I nee...
# general
p
Are there any astroid / pylint wizards here? I need to rework a pylint plugin so that it works with the pants assumption that transitive deps don't get imported. This plugin uses
__import__()
on matching classes to extract a dictionary property from the class. Here's the plugin https://github.com/st2sandbox/st2/blob/pants/pylint_plugins/api_models.py#L49-L52 Example matching class's
schema
property: https://github.com/st2sandbox/st2/blob/pants/st2common/st2common/models/system/actionchain.py#L125-L149 Maybe astroid provides a way to get the dictionary?
1
h
Jacob and I had been discussing this over DM: an alternative approach is to copy the Pants Pylint implementation and modify it to use transitive deps rather than direct deps Adjust Pants to your code, rather than adjusting your code to Pants
p
I just hacked together a modification for the pylint plugin that resolves most of the errors I was having. And a happy bonus is that relying only on the AST is a lot faster than importing modules over and over again. 😄
💯 2
Well, this version of the plugin uses the AST only so that
__import__
is no longer needed. That resolved hundreds of big ugly errors. Now there's just one error left for me to resolve, but this one is not caused by the pylint plugin. Hooray.
h
+1 for "Adjust Pants to your code, rather than adjusting your code to Pants"
p
I have had to clean up a variety of things in our code where the shortcuts taken made dependency inference difficult or impossible for pants. So, I might say "Adjust pants to your code where feasible before adjusting your code to pants".