Skip to content

Commit 41866f9

Browse files
authored
Merge pull request #412 from flpm/fix-reference-to-dependencies
docs: fix mistakes on mentions to how dependencies are defined in pyproject.toml
2 parents 8def4c1 + 79d1b66 commit 41866f9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

package-structure-code/declare-dependencies.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ within the code of your project or during development of your package.
3535

3636

3737
### 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`.
3939

4040
You will learn about both below.
4141

@@ -51,7 +51,7 @@ Within those 2 groups, there are three use cases that you can think about. 1. Co
5151
### Required (or core) dependencies
5252

5353
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.
5555

5656
### Optional dependencies
5757

@@ -120,7 +120,7 @@ dependencies = [
120120

121121
Ideally, you should only list the packages that are
122122
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
124124
additional packages that your users must install as well
125125
as the number of packages that depend upon your package
126126
must also install.
@@ -153,18 +153,18 @@ Optional dependencies for building your documentation, running your tests and bu
153153
* linting and other code cleanup tools
154154

155155
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.
157157

158158
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.
160160

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.
162162

163163
## Create optional dependency groups
164164

165165
To declare optional dependencies in your **pyproject.toml** file:
166166

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.
168168
2. Create named groups of dependencies using the syntax:
169169

170170
`group-name = ["dep1", "dep2"]`
@@ -223,9 +223,9 @@ feature = [
223223

224224
:::{figure-md} python-package-dependencies
225225

226-
<img src="../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+
<img src="../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 ">
227227

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.
229229
:::
230230

231231
:::{admonition} Using `python -m pip install` vs. `pip install`
@@ -250,15 +250,15 @@ groups that you defined above using the syntax:
250250

251251
Above you install:
252252
* dependencies needed for your documentation (`docs`),
253-
* required package dependencies in the `dependency` array and
253+
* required package dependencies in the `dependencies` array and
254254
* your package
255255

256256
using pip. Below you
257257
install your package, required dependencies and optional test dependencies.
258258

259259
`python -m pip install ".[tests]"`
260260

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:
262262

263263
`python -m pip install ".[docs, tests, lint]"`
264264

0 commit comments

Comments
 (0)