fpgmaas / deptry

Find unused, missing and transitive dependencies in a Python project.
https://deptry.com/
MIT License
800 stars 15 forks source link

Support multiple source roots #622

Open JettJones opened 3 months ago

JettJones commented 3 months ago

Is your feature request related to a problem? Please describe. I'm trying to run deptry on a project/monorepo setup with https://www.pantsbuild.org/

This leads to some broken expectations

So I can run deptry, and point to a shared requirements.txt file, but without defining import paths, I'll end up with hundreds of errors like:

`DEP001 'internal_library' imported but missing from the dependency definitions

Describe the solution you would like I'd like to be able to use deptry scanning directly with pants.toml defined requirements and multiple source paths. As a fall-back, being able to say give a broader PYTHONPATH like --source-roots ="./published/python:./libraries/python/" would help.

Additional context

There's likely an extension of this ask to other build tools like bazel.

fpgmaas commented 3 months ago

A solution that you could try today is using the known_first_party flag. This should resolve your DEP001 errors.

I wonder if the use case/ask for pointing to multiple roots is then still big enough. If so, I think it would make sense to first create a generic solution that is not specific to Pants. In this case, maybe an option would be to add include and extend-include flags, similar to ruff.

Then, if we want to support Pants.toml, we could read the dependencies and sources from that file, and have sources added to the include flag. On the other hand, I am also a bit cautious to add support for Pants.toml directly; It adds additional maintenance for a feature of which I am not sure it will be widely used. I guess that depends a bit on the amount of traction this issue gets.