142 points · by flo12392 · 2y ago · 24 comments
For those unfamiliar with deptry; deptry is a command line tool to check for issues with dependencies in a Python project, such as unused or missing dependencies.
GitHub: https://github.com/fpgmaas/deptry
For some benchmarks of the new release, see the release notes:
https://github.com/fpgmaas/deptry/releases/tag/0.14.0
The performance improvement was achieved by leveraging Rust to parse the AST and extract the import statements from .py files, rather than using Python's ast module.
The addition of Rust to the project also opens up doors for more optimizations in the future, so stay tuned!
The newest update was a delightful surprise since deptry is now fast enough to run during automated pull-request analysis via GitHub actions
1. DEP003 'click' imported but it is a transitive dependency (In my code base click is used @click - which it doesn't look like it sees)
2. DEP003 'numcodecs' imported but it is a transitive dependency Usage was open(...,compressor=numcodecs.xxx,...)
Perhaps these warnings/errors should be removed?
i.e. if I have
beautifulsoup4[html5lib,lxml]==4.12.3
in my requirements.txt and then import with from bs4 import BeautifulSoup
it would complainis there a way to configure that somehow?
aside from that, the tool is extremely fast
` Dependency 'beautifulsoup4' with top-levels: {'bs4'}.`
If you ever run into a situation where this does not work, you can use the `pacakge_module_name_map` parameter: https://fpgmaas.github.io/deptry/usage/#package-module-name-...
Hope this helps! Florian
Does it compare requirements.txt against imports, or checks if imports are actually used?
One thing to keep in mind, that would also be good for `deptry` to think about; if users decide to create a `requirements.txt` file from a `requirements.in` file, `deptry` will automatically use the `requirements.txt` file. However, this is wrong: It should use the `requirements.in` file, since the `requirements.txt` file also contains the transitive dependencies. Users can change this using the `requirements-txt` flag though (https://fpgmaas.github.io/deptry/usage/#requirements-txt).
Thanks for raising this, I will probably create an issue in our project to see how we should feal with this :)
What use case is this after? Linting in CI or similar?
I'd love a deeper way to identify and selectively reduce the cruft from projects though. For example currently I have about 180 dependencies in my project's .venv - most of them transitive.
These include things like the google-auth library when there is no code in my project that would ever need to talk to Google.
Mostly this is just wasteful and not a big issue, but then come the conflicting dependencies you need to resolve by pinning version numbers. This is doubly annoying if you have no idea what the dependency is needed for or even if it's needed at all.
This is not just a python issue, it's apparent in all languages I've worked in.