fpgmaas/deptry

Increase flexibility regarding development dependencies.

fpgmaas opened this issue · 5 comments

Inspired by this comment of @mkniewallner

#162 proposes to add support for PEP-621. However PEP-621 does not provide any standards for dealing with development dependencies. Currently, deptry has no implemented method to extract development dependencies for such a project.

AFAIK, there are now two main methods of specifying development dependencies for these projects:

  1. As a category/multiple categories under [project.optional-dependencies] in pyproject.toml. A drawback of this approach is that this adds an installation option to end-users, e.g. pip install package[dev], which may be undesirable.
  2. Outside of pyproject.toml, for example in a separate dev-requirements.txt

My initial proposal was to add a CLI command that allows the user to specify which entries under [project.optional-dependencies] are development dependencies, e.g.

[project.optional-dependencies]
develop = ["pytest", "pytest-cov"]
rest = ["docutils>=0.3", "pack ==1.1, ==1.3"]
deptry . --dependencies-dev-keys develop

I think we should implement this regardless of if we provide more flexibility. But this only supports (1) from the above listed ways to specify development dependencies. We might want to provide end-users with more flexibility regarding the detection of development dependencies than we currently support.

On the other hand, we should balance between flexibility and overengineering. I do think additional flexibility only is needed for projects that uses PEP-621 (for now), since for the other projects it's quite straightforward. Below a table of all reasonable combinations I think can occur.

requirements-dev.txt Poetry PDM [tool.pdm.dev-dependencies] PEP-621 [project.optional-dependencies]
requirements.txt x
Poetry x
PDM [project] dependencies x x
PEP-621 [project] dependencies x x

The above would lead me to the following solution;

  • Add a CLI argument to specify which entries under [project.optional-dependencies] are development dependencies.
  • If --requirements-txt-dev is specified, don't look for development dependencies in the tool itself, but parse them from that/those files.

This would be a great enhancement, my current solution is to comment out my dev and test dependencies before running deptry. What do you think about something like this?

[project.optional-dependencies]
pdf = ["pdf"]
dev = ["deptry"]
test = ["pytest"]

[tool.deptry]
# Exclude test + dev dependencies, include pdf
exclude-optional = ["dev", "test"]

I would love to see a feature like this in deptry. This is the only blocker that stops me from using this great tool in my project workflows.