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: package-structure-code/declare-dependencies.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ within the code of your project or during development of your package.
35
35
36
36
37
37
### Understanding optional vs. required dependencies
38
-
You can think about dependencies as being either optional or required. If they are required, they will be listed in the `[dependency] =` table of your `pyproject.toml` file. If they are optional, they will be listed in the `[optional.dependencies]` table of your `pyproject.toml`.
38
+
You can think about dependencies as being either optional or required. If they are required, they will be listed in the `dependencies` key in the `project` table of your `pyproject.toml` file. If they are optional, they will be listed in the `[optional.dependencies]` table of your `pyproject.toml`.
39
39
40
40
You will learn about both below.
41
41
@@ -51,7 +51,7 @@ Within those 2 groups, there are three use cases that you can think about. 1. Co
51
51
### Required (or core) dependencies
52
52
53
53
Required dependencies are called directly within your package's code. On this page we refer to these dependencies
54
-
as **core dependencies** as they are needed in order to run your package. You should place your core or required dependencies in the `[dependency]=` table of your `pyproject.toml` file.
54
+
as **core dependencies** as they are needed in order to run your package. You should place your core or required dependencies in the `dependencies` key of the `[project]` table of your `pyproject.toml` file.
55
55
56
56
### Optional dependencies
57
57
@@ -120,7 +120,7 @@ dependencies = [
120
120
121
121
Ideally, you should only list the packages that are
122
122
necessary to install and use your package in the
123
-
`[dependencies]`section. This minimizes the number of
123
+
`dependencies` key in the `[project]`table. This minimizes the number of
124
124
additional packages that your users must install as well
125
125
as the number of packages that depend upon your package
126
126
must also install.
@@ -153,18 +153,18 @@ Optional dependencies for building your documentation, running your tests and bu
153
153
* linting and other code cleanup tools
154
154
155
155
These dependencies are considered optional, because they are not required to install and use your package. Feature
156
-
dependencies are considered optional and should also be placed in the `[optional.dependencies]` table.
156
+
dependencies are considered optional and should also be placed in the `[project.optional-dependencies]` table.
157
157
158
158
Optional dependencies can be stored in an
159
-
`[optional.dependencies]` table in your **pyproject.toml** file.
159
+
`[project.optional-dependencies]` table in your **pyproject.toml** file.
160
160
161
-
It's important to note that within the `[optional.dependencies]` table, you can store additional, optional dependencies within named sub-groups. This is a different table than the dependencies array located within the `[project]` table discussed above which contains a single array with a single list of required packages.
161
+
It's important to note that within the `[project.optional-dependencies]` table, you can store additional, optional dependencies within named sub-groups. This is a different table than the dependencies array located within the `[project]` table discussed above which contains a single array with a single list of required packages.
162
162
163
163
## Create optional dependency groups
164
164
165
165
To declare optional dependencies in your **pyproject.toml** file:
166
166
167
-
1. Add a `[optional.dependencies]` table to your **pyproject.toml** file.
167
+
1. Add a `[project.optional-dependencies]` table to your **pyproject.toml** file.
168
168
2. Create named groups of dependencies using the syntax:
169
169
170
170
`group-name = ["dep1", "dep2"]`
@@ -223,9 +223,9 @@ feature = [
223
223
224
224
:::{figure-md} python-package-dependencies
225
225
226
-
<imgsrc="../images/python-package-dependencies.png"alt="Diagram showing a ven diagram with three sections representing the dependency groups listed above - docs feature and tests. In the center it says your-package and lists the core dependencies of that package seaborn and numpy. To the right are two arrows. The first shows the command python - m pip install your-package. It them shows how installing your package that way installs only the package and the two core dependencies into a users environment. Below is a second arrow with python -m pip install youPackage[tests]. This leads to an environment with both the package dependencies - your-package, seaborn and numpy and also the tests dependencies including pytest and pytest-cov ">
226
+
<imgsrc="../images/python-package-dependencies.png"alt="Diagram showing a Venn diagram with three sections representing the dependency groups listed above - docs feature and tests. In the center it says your-package and lists the core dependencies of that package seaborn and numpy. To the right are two arrows. The first shows the command python - m pip install your-package. It them shows how installing your package that way installs only the package and the two core dependencies into a users environment. Below is a second arrow with python -m pip install youPackage[tests]. This leads to an environment with both the package dependencies - your-package, seaborn and numpy and also the tests dependencies including pytest and pytest-cov ">
227
227
228
-
When a user installs your package locally using python -m pip install your-package only your package and it's core dependencies get installed. When they install your package `[tests]` pip will install both your package and its core dependencies plus any of the dependencies listed within the tests array of your `[optional.dependencies]` table.
228
+
When a user installs your package locally using `python -m pip install your-package` only your package and it's core dependencies get installed. When they install your package `python -m pip install your-package[tests]` pip will install both your package and its core dependencies plus any of the dependencies listed within the tests array of your `[project.optional-dependencies]` table.
229
229
:::
230
230
231
231
:::{admonition} Using `python -m pip install` vs. `pip install`
@@ -250,15 +250,15 @@ groups that you defined above using the syntax:
250
250
251
251
Above you install:
252
252
* dependencies needed for your documentation (`docs`),
253
-
* required package dependencies in the `dependency` array and
253
+
* required package dependencies in the `dependencies` array and
254
254
* your package
255
255
256
256
using pip. Below you
257
257
install your package, required dependencies and optional test dependencies.
258
258
259
259
`python -m pip install ".[tests]"`
260
260
261
-
You can install multiple dependency groups in the `[optional.dependencies]` table using:
261
+
You can install multiple dependency groups in the `[project.optional-dependencies]` table using:
0 commit comments