Hi, I ofter get messages from co-workers that do ...
# general
h
Hi, I ofter get messages from co-workers that do not know how to read CI logs that CI is broken. On some of the cases, it's because they have an automatic import by PyCharm that is just plain wrong, it looks like so:
Copy code
09:40:51.06 [ERROR] 1 Exception encountered:
UnownedDependencyError: Pants cannot infer owners for the following imports in the target path/to/file1.py:../../../my-package-sources:
  * this.is.a.bad.import.to.something (line: 18)

...
I'd like to add to their pre-commit-hook some pants command which will check that. Is there something that is fast that I can use? (something like
pants lint ::
but that will catch this use-case) I know that
pants test ::
catches it, but it runs all of the tests, which is way too much... (BTW, we currently use Pants 2.17)
๐Ÿงต
c
If this is the only unknown dependency, perhaps you could turn https://www.pantsbuild.org/2.17/reference/subsystems/python-infer#unowned_dependency_behavior into
error
and run
lint
?
h
I already have it configured and
pants lint ::
doesn't catch it, not sure why. I have
black
and
ruff
funning as linters, maybe I should add something else to trigger the check that I need?
c
oh, hmm... maybe
lint
doesn't examine dependencies.. so would need to run something that does.
perhaps (as a brute force of way)
pants peek :: >/dev/null
? (assuming any error is sent to
stderr
)
h
It does do the trick, thanks! ๐Ÿ™ ๐Ÿ™ ๐Ÿ™ Takes a bit of time though, I hope it won't be reverted due to it ๐Ÿ™ƒ
c
if it takes time during CI, hopefully the net effect is negligible from caching..
h
Actually, I'd like it to run locally for users every time they run
git commit ...
, and it will block the command from finishing until the
pants
command is done as well.
Technically, I'll make
git commit ...
internally run
pants lint [list of files] && pants peek [same list of files]
.
๐Ÿ‘ 1
h
We could add a fast "dependency lint" that just does dep inference
๐Ÿš€ 1
f
We could add a fast "dependency lint" that just does dep inference
interesting, would this goal be doing what
pants dependencies :: > /dev/null
does? We'd still need to evaluate the whole dep graph, right
perhaps (as a brute force of way)
pants peek :: >/dev/null
? (assuming any error is sent to
stderr
)
yes, I've been running
pants dependencies :: > /dev/null
myself exactly for the purposes of evaluating the dependency graph for any metadata related issues
n
Does this also help given that the inference warnings get cached - e.g. after the first run of
pants test ::
? I was wondering if there's a way to workaround that