https://pantsbuild.org/ logo
#general
Title
# general
p

proud-dentist-22844

07/11/2021, 9:42 AM
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
--no-process-execution-local-cleanup
shows that
st2client/st2client/models/keyvalue.py
is not included, which makes sense since it is not directly imported in
st2common/st2common/services/datastore.py
. Is there a way to get
*
imports to count as direct imports when pants is putting thing together for pylint?
h

hundreds-father-404

07/11/2021, 3:42 PM
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
p

proud-dentist-22844

07/11/2021, 4:40 PM
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
h

hundreds-father-404

07/11/2021, 9:40 PM
Excellent!! You can try running with --lint-per-file-caching to ensure it also works when each file is invoked separetely, rather than batched
p

proud-dentist-22844

07/11/2021, 9:48 PM
ooh! I didn't know about that option! Sweet
h

hundreds-father-404

07/11/2021, 10:16 PM
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