Hi everyone - I did a Slack search on this but cou...
# general
a
Hi everyone - I did a Slack search on this but couldn't turn anything up that seemed relevant/recent. I use pants for a python monorepo, and since pants knows my code's dependencies, can it tell me which third-party requirements are not referenced and likely unused? Hoping to use this to periodically prune our requirements files from packages which are no longer in use.
b
I’m not sure pants can do this automatically, but you can certainly do it by a custom script processing the output of
pants peek ::
, to find
python_requirement
targets that aren’t depended upon. NB however that https://github.com/pantsbuild/pants/issues/12733 will affect this: processing only that will only identify which of those targets aren’t used directly, they still might be used by another package… but, unless the requirements are being used to constrain versions, this is fine; the transitive deps will still be pulled in appropriately. If it matters, I’m sure we could brainstorm ideas to improve behaviour.
c
I think you could check them one by one.. i.e. something like
pants dependents 3rdparty/requirements#dist-name
👍 1
b
Ah, yeah, one could probably script a shell loop up with
pants list --filter-target-type=python_requirement ::
+ that
dependents
call. https://www.pantsbuild.org/docs/reference-filter#target_type
a
Thanks for the suggestion I'll give that a try and report back!
l
I did something similar but I was using Poetry as a source. Using Huon's suggestion, this might work:
Copy code
pants list --filter-target-type=python_requirement :: | xargs -I {} bash -c "pants -lerror dependees {} |  wc -l | grep -q '1' || echo '==> Kill {}'"
🤩 1