You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/dependency-specification.md
+170-1
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,87 @@ menu:
14
14
Dependencies for a project can be specified in various forms, which depend on the type
15
15
of the dependency and on the optional constraints that might be needed for it to be installed.
16
16
17
+
## `project.dependencies` and `tool.poetry.dependencies`
18
+
19
+
Prior Poetry 2.0, dependencies had to be declared in the `tool.poetry.dependencies`
20
+
section of the `pyproject.toml` file.
21
+
22
+
```toml
23
+
[tool.poetry.dependencies]
24
+
requests = "^2.13.0"
25
+
```
26
+
27
+
With Poetry 2.0, you should consider using the `project.dependencies` section instead.
28
+
29
+
```toml
30
+
[project]
31
+
# ...
32
+
dependencies = [
33
+
"requests (>=2.23.0,<3.0.0)"
34
+
]
35
+
```
36
+
37
+
While dependencies in `tool.poetry.dependencies` are specified using toml tables,
38
+
dependencies in `project.dependencies` are specified as strings according
39
+
to [PEP 508](https://peps.python.org/pep-0508/).
40
+
41
+
In many cases, `tool.poetry.dependencies` can be replaced with `project.dependencies`.
42
+
However, there are some cases where you might still need to use `tool.poetry.dependencies`.
43
+
For example, if you want to define additional information that is not required for building
44
+
but only for locking (for example an explicit source), you can enrich dependency
45
+
information in the `tool.poetry` section.
46
+
47
+
```toml
48
+
[project]
49
+
# ...
50
+
dependencies = [
51
+
"requests>=2.13.0",
52
+
]
53
+
54
+
[tool.poetry.dependencies]
55
+
requests = { source = "private-source" }
56
+
```
57
+
58
+
When both are specified, `project.dependencies` are used for metadata when building the project,
59
+
`tool.poetry.dependencies` is only used to enrich `project.dependencies` for locking.
60
+
61
+
Alternatively, you can add `dependencies` to `dynamic` and define your dependencies
62
+
completely in the `tool.poetry` section. Using only the `tool.poetry` section might
63
+
make sense in non-package mode when you will not build an sdist or a wheel.
64
+
65
+
```toml
66
+
[project]
67
+
# ...
68
+
dynamic = [ "dependencies" ]
69
+
70
+
[tool.poetry.dependencies]
71
+
requests = { version = ">=2.13.0", source = "private-source" }
72
+
```
73
+
74
+
{{% note %}}
75
+
Another use case for `tool.poetry.dependencies` are relative path dependencies
76
+
since `project.dependencies` only support absolute paths.
77
+
{{% /note %}}
78
+
79
+
{{% note %}}
80
+
Only main dependencies can be specified in the `project` section.
81
+
Other [Dependency groups]({{< relref "managing-dependencies#dependency-groups" >}})
82
+
must still be specified in the `tool.poetry` section.
83
+
{{% /note %}}
84
+
17
85
## Version constraints
18
86
87
+
{{% warning %}}
88
+
Some of the following constraints can only be used in `tool.poetry.dependencies` and not in `project.dependencies`.
89
+
When using `poetry add` such constraints are automatically converted into an equivalent constraint.
90
+
{{% /warning %}}
91
+
19
92
### Caret requirements
20
93
94
+
{{% warning %}}
95
+
Not supported in `project.dependencies`.
96
+
{{% /warning %}}
97
+
21
98
**Caret requirements** allow [SemVer](https://semver.org/) compatible updates to a specified version. An update is allowed if the new version number does not modify the left-most non-zero digit in the major, minor, patch grouping. For instance, if we previously ran `poetry add requests@^2.13.0` and wanted to update the library and ran `poetry update requests`, poetry would update us to version `2.14.0` if it was available, but would not update us to `3.0.0`. If instead we had specified the version string as `^0.1.13`, poetry would update to `0.1.14` but not `0.2.0`. `0.0.x` is not considered compatible with any other version.
22
99
23
100
Here are some more examples of caret requirements and the versions that would be allowed with them:
@@ -34,6 +111,10 @@ Here are some more examples of caret requirements and the versions that would be
34
111
35
112
### Tilde requirements
36
113
114
+
{{% warning %}}
115
+
Not supported in `project.dependencies`.
116
+
{{% /warning %}}
117
+
37
118
**Tilde requirements** specify a minimal version with some ability to update.
38
119
If you specify a major, minor, and patch version or only a major and minor version, only patch-level changes are allowed.
39
120
If you only specify a major version, then minor- and patch-level changes are allowed.
@@ -131,6 +212,16 @@ the minimum information you need to specify is the location of the repository wi
In cases where the package you want to install is located in a subdirectory of the VCS repository, you can use the `subdirectory` option, similarly to what [pip](https://pip.pypa.io/en/stable/topics/vcs-support/#url-fragments) provides:
Copy file name to clipboardexpand all lines: docs/faq.md
+12
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,18 @@ Usually you will want to match the supported Python range of your project with t
211
211
Alternatively you can tell Poetry to install this dependency [only for a specific range of Python versions]({{< relref "dependency-specification#multiple-constraints-dependencies" >}}),
212
212
if you know that it's not needed in all versions.
213
213
214
+
If you do not want to set an upper bound in the metadata when building your project,
215
+
you can omit it in the `project` section and only set it in `tool.poetry.dependencies`:
216
+
217
+
```toml
218
+
[project]
219
+
# ...
220
+
requires-python = ">=3.7"# used for metadata when building the project
221
+
222
+
[tool.poetry.dependencies]
223
+
python = ">=3.7,<3.11"# used for locking dependencies
0 commit comments