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: _sources/package-structure-code/declare-dependencies.md.txt
+11-11Lines changed: 11 additions & 11 deletions
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
-
<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 ">
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:
<h3>Understanding optional vs. required dependencies<aclass="headerlink" href="#understanding-optional-vs-required-dependencies" title="Link to this heading">#</a></h3>
531
-
<p>You can think about dependencies as being either optional or required. If they are required, they will be listed in the <codeclass="docutils literal notranslate"><spanclass="pre">[dependency]</span><spanclass="pre">=</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code> file. If they are optional, they will be listed in the <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code>.</p>
531
+
<p>You can think about dependencies as being either optional or required. If they are required, they will be listed in the <codeclass="docutils literal notranslate"><spanclass="pre">dependencies</span></code> key in the <codeclass="docutils literal notranslate"><spanclass="pre">project</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code> file. If they are optional, they will be listed in the <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code>.</p>
<h3>Required (or core) dependencies<aclass="headerlink" href="#required-or-core-dependencies" title="Link to this heading">#</a></h3>
543
543
<p>Required dependencies are called directly within your package’s code. On this page we refer to these dependencies
544
-
as <strong>core dependencies</strong> as they are needed in order to run your package. You should place your core or required dependencies in the <codeclass="docutils literal notranslate"><spanclass="pre">[dependency]=</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code> file.</p>
544
+
as <strong>core dependencies</strong> as they are needed in order to run your package. You should place your core or required dependencies in the <codeclass="docutils literal notranslate"><spanclass="pre">dependencies</span></code> key of the <codeclass="docutils literal notranslate"><spanclass="pre">[project]</span></code> table of your <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code> file.</p>
545
545
</section>
546
546
<sectionid="optional-dependencies">
547
547
<h3>Optional dependencies<aclass="headerlink" href="#optional-dependencies" title="Link to this heading">#</a></h3>
@@ -601,7 +601,7 @@ <h3>Add required dependencies to your pyproject.toml file<a class="headerlink" h
601
601
</div>
602
602
<p>Ideally, you should only list the packages that are
603
603
necessary to install and use your package in the
604
-
<codeclass="docutils literal notranslate"><spanclass="pre">[dependencies]</span></code>section. This minimizes the number of
604
+
<codeclass="docutils literal notranslate"><spanclass="pre">dependencies</span></code> key in the <codeclass="docutils literal notranslate"><spanclass="pre">[project]</span></code>table. This minimizes the number of
605
605
additional packages that your users must install as well
606
606
as the number of packages that depend upon your package
607
607
must also install.</p>
@@ -629,17 +629,17 @@ <h3>Optional dependencies<a class="headerlink" href="#id2" title="Link to this h
629
629
<li><p>linting and other code cleanup tools</p></li>
630
630
</ul>
631
631
<p>These dependencies are considered optional, because they are not required to install and use your package. Feature
632
-
dependencies are considered optional and should also be placed in the <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table.</p>
632
+
dependencies are considered optional and should also be placed in the <codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table.</p>
633
633
<p>Optional dependencies can be stored in an
634
-
<codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table in your <strong>pyproject.toml</strong> file.</p>
635
-
<p>It’s important to note that within the <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table, you can store additional, optional dependencies within named sub-groups. This is a different table than the dependencies array located within the <codeclass="docutils literal notranslate"><spanclass="pre">[project]</span></code> table discussed above which contains a single array with a single list of required packages.</p>
634
+
<codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table in your <strong>pyproject.toml</strong> file.</p>
635
+
<p>It’s important to note that within the <codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table, you can store additional, optional dependencies within named sub-groups. This is a different table than the dependencies array located within the <codeclass="docutils literal notranslate"><spanclass="pre">[project]</span></code> table discussed above which contains a single array with a single list of required packages.</p>
636
636
</section>
637
637
</section>
638
638
<sectionid="create-optional-dependency-groups">
639
639
<h2>Create optional dependency groups<aclass="headerlink" href="#create-optional-dependency-groups" title="Link to this heading">#</a></h2>
640
640
<p>To declare optional dependencies in your <strong>pyproject.toml</strong> file:</p>
641
641
<olclass="arabic simple">
642
-
<li><p>Add a <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table to your <strong>pyproject.toml</strong> file.</p></li>
642
+
<li><p>Add a <codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table to your <strong>pyproject.toml</strong> file.</p></li>
643
643
<li><p>Create named groups of dependencies using the syntax:</p></li>
<h3>Install dependency groups<aclass="headerlink" href="#install-dependency-groups" title="Link to this heading">#</a></h3>
688
688
<figureclass="align-default" id="id3">
689
-
<imgalt="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" src="../_images/python-package-dependencies.png" />
689
+
<imgalt="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" src="../_images/python-package-dependencies.png" />
690
690
<figcaption>
691
-
<p><spanclass="caption-text">When a user installs your package locally using python -m pipinstallyour-package only your package and it’s core dependencies get installed. When they install your package <codeclass="docutils literal notranslate"><spanclass="pre">[tests]</span></code> pip will install both your package and its core dependencies plus any of the dependencies listed within the tests array of your <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table.</span><aclass="headerlink" href="#id3" title="Link to this image">#</a></p>
691
+
<p><spanclass="caption-text">When a user installs your package locally using <codeclass="docutils literal notranslate"><spanclass="pre">python</span><spanclass="pre">-m</span><spanclass="pre">pip</span><spanclass="pre">install</span><spanclass="pre">your-package</span></code> only your package and it’s core dependencies get installed. When they install your package <codeclass="docutils literal notranslate"><spanclass="pre">python</span><spanclass="pre">-m</span><spanclass="pre">pip</span><spanclass="pre">install</span><spanclass="pre">your-package[tests]</span></code> pip will install both your package and its core dependencies plus any of the dependencies listed within the tests array of your <codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table.</span><aclass="headerlink" href="#id3" title="Link to this image">#</a></p>
<p>You can install multiple dependency groups in the <codeclass="docutils literal notranslate"><spanclass="pre">[optional.dependencies]</span></code> table using:</p>
717
+
<p>You can install multiple dependency groups in the <codeclass="docutils literal notranslate"><spanclass="pre">[project.optional-dependencies]</span></code> table using:</p>
0 commit comments