OK. My last issue with pylint + pants. An edge cas...
# general
OK. My last issue with pylint + pants. An edge case where pylint needs some transitive deps due to some
from ... import *
imports. This import: https://github.com/st2sandbox/st2/blob/pants/st2common/st2common/services/datastore.py#L22
Copy code
from st2client.models import KeyValuePair
comes from this file (yes I have
[python-infer].inits = true
in pants.toml): https://github.com/st2sandbox/st2/blob/pants/st2client/st2client/models/__init__.py#L25
Copy code
from st2client.models.keyvalue import *  # noqa
which brings in the transitive dep: https://github.com/st2sandbox/st2/blob/pants/st2client/st2client/models/keyvalue.py#L26
Copy code
class KeyValuePair(core.Resource):
If I run the full suite with
./pants lint ::
, pylint succeeds (except for a known real failure somewhere else). But using a narrow target:
./pants lint ./st2common/st2common/services::
pylint fails with:
Copy code
st2common/st2common/services/datastore.py:22:0: E0611: No name 'KeyValuePair' in module 'st2client.models' (no-name-in-module)
Inspecting the process-execution dir with
shows that
is not included, which makes sense since it is not directly imported in
. Is there a way to get
imports to count as direct imports when pants is putting thing together for pylint?
No i don't think we can reliably update Pants here. Instead, I recommend either adding that dependency as an explicit dependency in the BUILD file, or refactoring the code to not use star imports Or, rewrite Pylint implementation to pull in transitive deps instead of direct
I don't like the idea of forking the pylint stuff. I'm ok with some the BUILD dependency though.
I'll try that later
I refactored the code to not depend on the
imports. That made it more consistent and predictable. Plus, now pylint passes on every directory when pants runs it 😄. That's been a long time coming!
❤️ 1
Excellent!! You can try running with --lint-per-file-caching to ensure it also works when each file is invoked separetely, rather than batched
ooh! I didn't know about that option! Sweet
It's likely going to make things slower, so probably not a great default for desktop builds. Possibly valuable to enable in CI to ensure things always work tho