Skip to content

Commit 1837f6f

Browse files
authored
docs: better showcase supported dependency managers (#895)
* docs: add page to showcase supported dependency managers * docs: US english
1 parent 596a7be commit 1837f6f

File tree

3 files changed

+213
-40
lines changed

3 files changed

+213
-40
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Supported dependency managers
2+
3+
While most dependency managers support the
4+
standard [PEP 621 format](https://packaging.python.org/en/latest/specifications/pyproject-toml/) for defining
5+
dependencies in `pyproject.toml`, not all of them do. Even those that do often provide additional ways to define
6+
dependencies that are not standardized.
7+
8+
_deptry_ can extract dependencies from most of the package managers that support PEP
9+
621 (e.g. [uv](https://docs.astral.sh/uv/), [PDM](https://pdm-project.org/en/latest/)), including tool-specific
10+
extensions, but also from package managers that do not (or used to not) support PEP
11+
621 (e.g. [Poetry](https://python-poetry.org/), [pip](https://pip.pypa.io/en/stable/reference/requirements-file-format/)).
12+
13+
## PEP 621
14+
15+
_deptry_ fully supports [PEP 621 standard](https://packaging.python.org/en/latest/specifications/pyproject-toml/), and
16+
use the presence of a `[project]` section in `pyproject.toml` to determine that the project uses PEP 621.
17+
18+
By default, _deptry_ extracts, from `pyproject.toml`:
19+
20+
- regular dependencies from:
21+
- `dependencies` entry under `[project]` section
22+
- groups under `[project.optional-dependencies]` section
23+
- development dependencies from groups under `[dependency-groups]` section
24+
25+
For instance, with this `pyproject.toml`:
26+
27+
```toml title="pyproject.toml"
28+
[project]
29+
name = "foo"
30+
dependencies = ["orjson>=3.0.0"]
31+
32+
[project.optional-dependencies]
33+
cli = ["click>=8.0.0"]
34+
http = [
35+
"httpx>=0.27.0",
36+
"uvicorn>=0.32.0",
37+
]
38+
39+
[dependency-groups]
40+
docs = ["mkdocs==1.6.1"]
41+
test = [
42+
"pytest==8.3.3",
43+
"pytest-cov==5.0.0",
44+
]
45+
```
46+
47+
the following dependencies will be extracted:
48+
49+
- regular dependencies: `orjson`, `click`, `httpx`, `uvicorn`
50+
- development dependencies: `mkdocs`, `pytest`, `pytest-cov`
51+
52+
!!! note
53+
54+
Groups under `[project.optional-dependencies]` can be flagged as development dependency groups by
55+
using [`--pep621-dev-dependency-groups`](usage.md#pep-621-dev-dependency-groups) argument (or its
56+
`pep_621_dev_dependency_groups` equivalent in `pyproject.toml`).
57+
58+
### uv
59+
60+
Additionally to PEP 621 dependencies, _deptry_ will
61+
extract [uv development dependencies](https://docs.astral.sh/uv/concepts/dependencies/#development-dependencies) from
62+
`dev-dependencies` entry under `[tool.uv]` section, for instance:
63+
64+
```toml title="pyproject.toml"
65+
[tool.uv]
66+
dev-dependencies = [
67+
"mkdocs==1.6.1",
68+
"pytest==8.3.3",
69+
"pytest-cov==5.0.0",
70+
]
71+
```
72+
73+
### PDM
74+
75+
Additionally to PEP 621 dependencies, _deptry_ will
76+
extract [PDM development dependencies](https://pdm-project.org/en/latest/usage/dependency/#add-development-only-dependencies)
77+
from `[tool.pdm.dev-dependencies]` section, for instance:
78+
79+
```toml title="pyproject.toml"
80+
[tool.pdm.dev-dependencies]
81+
docs = ["mkdocs==1.6.1"]
82+
test = [
83+
"pytest==8.3.3",
84+
"pytest-cov==5.0.0",
85+
]
86+
```
87+
88+
### Setuptools
89+
90+
When using setuptools as a build backend, both `dependencies` and `optional-dependencies` can
91+
be [dynamically read](https://setuptools.pypa.io/en/stable/userguide/pyproject_config.html#dynamic-metadata) from
92+
`requirements.txt`-format files, for instance:
93+
94+
```toml title="pyproject.toml"
95+
[build-backend]
96+
requires = ["setuptools"]
97+
build-backend = "setuptools.build_meta"
98+
99+
[project]
100+
name = "foo"
101+
dynamic = ["dependencies", "optional-dependencies"]
102+
103+
[tool.setuptools.dynamic]
104+
dependencies = { file = ["requirements.txt"] }
105+
106+
[tool.setuptools.dynamic.optional-dependencies]
107+
cli = { file = ["cli-requirements.txt"] }
108+
```
109+
110+
In this example, regular dependencies will be extracted from both `requirements.txt` and `cli-requirements.txt` files.
111+
112+
!!! note
113+
114+
Groups under `[tool.setuptools.dynamic.optional-dependencies]` can be flagged as development dependency groups by
115+
using [`--pep621-dev-dependency-groups`](usage.md#pep-621-dev-dependency-groups) argument (or its
116+
`pep_621_dev_dependency_groups` equivalent in `pyproject.toml`).
117+
118+
## Poetry
119+
120+
_deptry_ supports
121+
extracting [dependencies defined using Poetry](https://python-poetry.org/docs/pyproject/#dependencies-and-dependency-groups),
122+
and uses the presence of a `[tool.poetry.dependencies]` section in `pyproject.toml` to determine that the project uses
123+
Poetry.
124+
125+
In a `pyproject.toml` file where Poetry is used, _deptry_ will extract:
126+
127+
- regular dependencies from entries under `[tool.poetry.dependencies]` section
128+
- development dependencies from entries under each `[tool.poetry.group.<group>.dependencies]` section (or the
129+
legacy `[tool.poetry.dev-dependencies]` section)
130+
131+
For instance, given the following `pyproject.toml` file:
132+
133+
```toml title="pyproject.toml"
134+
[tool.poetry.dependencies]
135+
python = "^3.10"
136+
orjson = "^3.0.0"
137+
click = { version = "^8.0.0", optional = true }
138+
139+
[tool.poetry.extras]
140+
cli = ["click"]
141+
142+
[tool.poetry.group.docs.dependencies]
143+
mkdocs = "1.6.1"
144+
145+
[tool.poetry.group.test.dependencies]
146+
pytest = "8.3.3"
147+
pytest-cov = "5.0.0"
148+
```
149+
150+
the following dependencies will be extracted:
151+
152+
- regular dependencies: `orjson`, `click`
153+
- development dependencies: `mkdocs`, `pytest`, `pytest-cov`
154+
155+
## `requirements.txt` (pip, pip-tools)
156+
157+
_deptry_ supports extracting [dependencies using
158+
`requirements.txt` format](https://pip.pypa.io/en/stable/reference/requirements-file-format/), which is mostly used
159+
by [pip](https://pip.pypa.io/en/stable/) and [pip-tools](https://pip-tools.readthedocs.io/en/stable/).
160+
161+
By default, _deptry_ will look for:
162+
163+
- regular dependencies in `requirements.txt` (or `requirements.in` if existing, assuming pip-tools is used)
164+
- development dependencies in `dev-requirements.txt` and `requirements-dev.txt`
165+
166+
For instance, given the following `requirements.txt` file:
167+
168+
```python title="requirements.txt"
169+
click>=8.0.0
170+
orjson>=3.0.0
171+
```
172+
173+
and the following `dev-requirements.txt` file:
174+
175+
```python title="dev-requirements.txt"
176+
mkdocs==1.6.1
177+
pytest==8.3.3
178+
pytest-cov==5.0.0
179+
```
180+
181+
the following dependencies will be extracted:
182+
183+
- regular dependencies: `click`, `orjson`
184+
- development dependencies: `mkdocs`, `pytest`, `pytest-cov`
185+
186+
!!! note
187+
188+
If using different files for regular dependencies, [`--requirements-files`](usage.md#requirements-files) (or its
189+
`requirements_files` equivalent in `pyproject.toml`) can be used to instruct _deptry_ about the requirements files
190+
locations. Similarly, [`--requirements-files-dev`](usage.md#requirements-files-dev) (or its `requirements_files_dev`
191+
equivalent in `pyproject.toml`) can be used for requirements files containing development dependencies.

docs/usage.md

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,17 @@ If you want to configure _deptry_ using `pyproject.toml`, or if your dependencie
2020

2121
## Dependencies extraction
2222

23-
_deptry_ extracts dependencies into 2 separate groups:
23+
_deptry_ can extract dependencies from a broad range of [dependency managers](supported-dependency-managers.md).
2424

25-
- "production" ones, meant to be used in the codebase
25+
Dependencies are always extracted into two separate groups:
26+
27+
- regular ones, meant to be used in the codebase
2628
- development ones
2729

2830
This is an important distinction, as development dependencies are usually meant to only be used outside the
29-
codebase (for instance in tests, or as CLI tools for type-checking, formatting, etc.). For this reason, _deptry_ will
31+
codebase (e.g. `pytest` to run tests, Mypy for type-checking, or Ruff for formatting). For this reason, _deptry_ will
3032
not run [Unused dependencies (DEP002)](rules-violations.md#unused-dependencies-dep002) for development dependencies.
3133

32-
To determine the project's dependencies, _deptry_ will scan the directory it is run from for files in the following order:
33-
34-
1. If a `pyproject.toml` file with a `[tool.poetry.dependencies]` section is found, _deptry_ will assume it uses Poetry and extract:
35-
- dependencies from `[tool.poetry.dependencies]` section
36-
- development dependencies from `[tool.poetry.group.dev.dependencies]` or `[tool.poetry.dev-dependencies]` section
37-
1. If a `pyproject.toml` file with a `[tool.pdm.dev-dependencies]` section is found, _deptry_ will assume it uses PDM and extract:
38-
- dependencies from `[project.dependencies]` and `[project.optional-dependencies]` sections
39-
- development dependencies from `[tool.pdm.dev-dependencies]` section and from the groups under `[project.optional-dependencies]` passed via the [`--pep621-dev-dependency-groups`](#pep-621-dev-dependency-groups) argument
40-
1. If a `pyproject.toml` file with a `[tool.uv.dev-dependencies]` section is found, _deptry_ will assume it uses uv and extract:
41-
- dependencies from `[project.dependencies]` and `[project.optional-dependencies]` sections
42-
- development dependencies from `[tool.uv.dev-dependencies]` section and from the groups under `[project.optional-dependencies]` passed via the [`--pep621-dev-dependency-groups`](#pep-621-dev-dependency-groups) argument
43-
1. If a `pyproject.toml` file with a `[project]` section is found, _deptry_ will assume it uses [PEP 621](https://peps.python.org/pep-0621/) for dependency specification and extract:
44-
- dependencies from:
45-
- `[project.dependencies]` (or `dependencies` requirements files under `[tool.setuptools.dynamic]` section if the project uses `setuptools.build_meta` as a build backend, and a `dynamic` key under `[project]` section includes `"dependencies"`)
46-
- `[project.optional-dependencies]` (or requirements files under `[tool.setuptools.dynamic.optional-dependencies]` section if the project uses `setuptools.build_meta` as a build backend, and a `dynamic` key under `[project]` section includes `"optional-dependencies"`)
47-
- development dependencies from the groups under `[dependency-groups]`, and the ones under `[project.optional-dependencies]` (or `setuptools` equivalent) passed via the [`--pep621-dev-dependency-groups`](#pep-621-dev-dependency-groups) argument
48-
1. If a `requirements.in` or `requirements.txt` file is found, _deptry_ will:
49-
- extract dependencies from that file.
50-
- extract development dependencies from `dev-dependencies.txt` and `dependencies-dev.txt`, if any exist
51-
52-
_deptry_ can be configured to look for `pip` requirements files with other names or in other directories.
53-
See [Requirements files](#requirements-files) and [Requirements files dev](#requirements-files-dev).
54-
5534
## Imports extraction
5635

5736
_deptry_ will search for imports in Python files (`*.py`, and `*.ipynb` unless [`--ignore-notebooks`](#ignore-notebooks)
@@ -456,30 +435,32 @@ deptry . --package-module-name-map "foo-python=foo,bar-python=bar"
456435

457436
#### PEP 621 dev dependency groups
458437

459-
PEP 621 does [not define](https://peps.python.org/pep-0621/#recommend-that-tools-put-development-related-dependencies-into-a-dev-extra) a standard convention for specifying development dependencies. However, deptry offers a mechanism to interpret specific optional dependency groups as development dependencies.
438+
Historically, PEP 621
439+
did [not define](https://peps.python.org/pep-0621/#recommend-that-tools-put-development-related-dependencies-into-a-dev-extra)
440+
a standard convention for specifying development dependencies. [PEP 735](https://peps.python.org/pep-0735/) now covers
441+
this, but in the meantime, several projects defined development dependencies under `[project.optional-dependencies]`.
442+
_deptry_ offers a mechanism to interpret specific optional dependency groups as development dependencies.
460443

461-
By default, all dependencies under `[project.dependencies]` and `[project.optional-dependencies]` are extracted as regular dependencies. By using the `--pep621-dev-dependency-groups` argument, users can specify which groups defined under `[project.optional-dependencies]` should be treated as development dependencies instead. This is particularly useful for projects that adhere to PEP 621 but do not employ a separate build tool for declaring development dependencies.
444+
By default, all dependencies under `[project.dependencies]` and `[project.optional-dependencies]` are extracted as
445+
regular dependencies. By using the `--pep621-dev-dependency-groups` argument, users can specify which groups defined
446+
under `[project.optional-dependencies]` should be treated as development dependencies instead. This is particularly
447+
useful for projects that adhere to PEP 621 but do not employ a separate build tool for declaring development
448+
dependencies.
462449

463450
For example, consider a project with the following `pyproject.toml`:
464451

465452
```toml
466453
[project]
467454
...
468-
dependencies = [
469-
"httpx",
470-
]
455+
dependencies = ["httpx"]
471456
472457
[project.optional-dependencies]
473-
test = [
474-
"pytest < 5.0.0",
475-
]
476-
plot = [
477-
"matplotlib",
478-
]
458+
plot = ["matplotlib"]
459+
test = ["pytest"]
479460
```
480461

481-
By default, `httpx`, `pytest` and `matplotlib` are extracted as regular dependencies. By specifying `--pep621-dev-dependency-groups=test`,
482-
the dependency `pytest` will be considered a development dependency instead.
462+
By default, `httpx`, `matplotlib` and `pytest` are extracted as regular dependencies. By specifying
463+
`--pep621-dev-dependency-groups=test`, `pytest` dependency will be treated as a development dependency instead.
483464

484465
- Type: `list[str]`
485466
- Default: `[]`
@@ -498,7 +479,7 @@ deptry . --pep621-dev-dependency-groups "test,docs"
498479
#### Experimental namespace package
499480

500481
!!! warning
501-
This option is experimental and disabled by default for now, as it could degrade performance in large codebases.
482+
This option is experimental and disabled by default for now, as it could degrade performance in large codebases.
502483

503484
Enable experimental namespace package ([PEP 420](https://peps.python.org/pep-0420/)) support.
504485

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ nav:
1111
- Home: index.md
1212
- Usage and Configuration: usage.md
1313
- Rules and Violations: rules-violations.md
14+
- Supported dependency managers: supported-dependency-managers.md
1415
- Changelog: CHANGELOG.md
1516
- Contributing: contributing.md
1617

0 commit comments

Comments
 (0)