fpgmaas / deptry

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

Increase flexibility regarding development dependencies. #168

Closed fpgmaas closed 6 months ago

fpgmaas commented 1 year ago

Inspired by this comment of @mkniewallner

https://github.com/fpgmaas/deptry/issues/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
fpgmaas commented 1 year ago

The above would lead me to the following solution;

eelcovdw commented 1 year ago

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"]
qthequartermasterman commented 1 year ago

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.

adamtheturtle commented 6 months ago

While this issue is unresolved, I have the following in my linting setup (requires uv):

uv pip compile --no-deps pyproject.toml > $(TEMPFILE)
mv pyproject.toml pyproject.bak.toml
deptry --requirements-txt=$(TEMPFILE) src/ || (mv pyproject.bak.toml pyproject.toml && exit 1)
mv pyproject.bak.toml pyproject.toml
fpgmaas commented 6 months ago

I started implementing a flag to allow users to specify which groups under [project.optional-dependencies] should be considered development dependencies. First draft PR here: https://github.com/fpgmaas/deptry/pull/628/files

It proposes to add a flag called --pep621-dev-dependency-groups.