Skip to content

Commit 29b1194

Browse files
committed
Fix: a few fixes from Jeremiah
1 parent 94324bc commit 29b1194

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

package-structure-code/declare-dependencies.md

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
1-
# Python package dependency declaration
1+
# Declaring Development Dependencies - Python Packaging
22

33
## How to declare documentation, test and other deps
44

5-
It is currently recommended that you store all dependency information in a **pyproject.toml** file.
5+
In the [pyproject.toml overview page](pyproject-toml-python-package-metadata) we discussed how to setup a pyproject.toml file with basic metadata information.
6+
On this page, you will learn about storing and accessing dependency information within the pyproject.toml file.
7+
8+
It is recommended that you store all dependency information in a **pyproject.toml** file (with a few caveats).
9+
610
This ensures that all of the metadata associated with your package is declared in a single place, making it simpler for users and contributors to understand your package infrastructure.
711

8-
Dependencies for building your documentation, running your tests and building your package's distribution files can be stored in a `[optional.dependencies]` table within the **pyproject.toml** file.
12+
## Direct project dependencies
13+
14+
Your core project dependencies - representing the packages that
15+
a user requires to install your package, can be stored in a
16+
dependencies array located within the `[project]` table of your
17+
pyproject.toml file. This looks something like this:
18+
19+
````toml
20+
[project]
21+
name = "examplePy"
22+
authors = [
23+
{name = "Some Maintainer", email = "[email protected]"},
24+
]
25+
# more metadata here...
26+
dependencies = [
27+
"rioxarray",
28+
"geopandas",
29+
]
30+
```
31+
32+
## Development dependencies
33+
34+
Dependencies for building your documentation, running your tests and building your package's distribution files are often referred to as development dependencies. These are the dependnecies that a user needs to run core development elements of your package such as:
35+
36+
* running your test suite
37+
* building your documentation
38+
* linting and other code cleanup tools
39+
40+
These dependencies can be stored in an
41+
`[optional.dependencies]` table within the **pyproject.toml** file.
942

1043
```{admonition} What happened to the requirements.txt file for dependencies?
1144
:class: note
1245

13-
The requirements.txt file used to be the default way to store dependencies. However in recent years, the ecosystem has moved to storing all of this information in a single **pyproject.toml** file.
14-
```
46+
The requirements.txt file used to be the default way to store dependencies. However in recent years, the ecosystem has moved to storing all of this information in a single **pyproject.toml** file. You may find that some projects do still maintain a requirements.txt file either for specific local development needs OR to support users who may want to create a pip-based virtual environment.
47+
````
48+
49+
## How to declare development dependencies
1550

1651
To declare dependencies in your **pyproject.toml** file:
1752

@@ -48,17 +83,22 @@ lint = [
4883

4984
## How to install dependencies from your pyproject.toml
5085

51-
You can then install the dependencies via individual groups using:
86+
You can install development dependencies using the
87+
groups that you defined above using the syntax:
5288

53-
`pip install yourPackage.[docs]`
89+
`pip install .[docs]`
5490

55-
or you could install just the dependencies for your tests using:
91+
Above you install the dependencies needed for your documentation and also your package using pip. Below you
92+
install just the dependencies needed to run your tests:
5693

57-
`pip install yourPackage.[tests]`
94+
`pip install .[tests]`
5895

5996
You can install all dependencies in the `[optional.dependencies]` table using:
6097

61-
`yourPackage.[all]`
98+
`pip install .[docs, tests, lint]`
99+
100+
Each time you call `pip install .[groups-here]`, you are also installing your package locally and also any dependencies
101+
that your package needs / has declared in your pyproject.toml file.
62102

63103
```{admonition} For zsh shell users
64104
:class: tip
@@ -85,9 +125,10 @@ dev = [
85125
]
86126
```
87127

88-
You can also install subsets of dependencies like this:
128+
The above allows you to install both the tests and docs dependency lists
129+
using the command:
89130

90-
`pip install .[tests, docs]`
131+
`pip install .[dev]`
91132

92133
```{tip}
93134
When you install dependencies using the above syntax:
@@ -101,11 +142,9 @@ pip will also install both your package and its core dependencies.
101142

102143
The above workflow assumes that you want to publish your package on PyPI. And then you plan to publish to conda-forge (optionally), [by submitting a recipe using greyskull](https://www.pyopensci.org/python-package-guide/package-structure-code/publish-python-package-pypi-conda.html).
103144

104-
If you want to support conda users, you may want to also maintain a conda environment that they can use to install your package. Maintaning a conda environment will also help you test that your package installs as you expect into a conda environment.
105-
106-
## Read the Docs & Python Environments
145+
If you want to support conda users, you may want to also maintain a conda environment that they can use to install your package. Maintaining a conda environment will also help you test that your package installs as you expect into a conda environment.
107146

108-
TODO: we will link to this config section from the RTD page as well...
147+
## Read the Docs & project dependencies
109148

110149
If you are using readthedocs to build your documentation, then you may need to install your dependencies using a **readthedocs.yaml** file.
111150

@@ -129,7 +168,7 @@ python:
129168

130169
The above should work if you are using a vanilla packaging approach with a tool such as the [PyPA build tool](https://pypa-build.readthedocs.io/en/stable/) and any back-end that works with `build`.
131170

132-
If you are using another front-end build tool such as PDM, Hatch or Poetry to manage dependencies, then your approach to installing dependencies may be different. Each tool has its own, slightly different way of declaring dependencies in the **pyproject.toml** file. You can learn more about [configuing RTD for tools such as Poetry and PDM here.](https://docs.readthedocs.io/en/stable/build-customization.html#install-dependencies-with-poetry)
171+
If you are using another front-end build tool such as PDM, Hatch or Poetry to manage dependencies, then your approach to installing dependencies may be different. Each tool has its own, slightly different way of declaring dependencies in the **pyproject.toml** file. You can learn more about [configuring RTD for tools such as Poetry and PDM here.](https://docs.readthedocs.io/en/stable/build-customization.html#install-dependencies-with-poetry)
133172

134173
```{admonition} A note for conda users
135174
:class: tip
@@ -138,5 +177,5 @@ If you use a conda environment for developing your tool, keep in mind that when
138177
139178
Thus, if you are running a conda environment, installing your package in editable mode risks dependency conflicts. This is particularly important if you have a spatial package that required GDAL or has a GDAL supported dependency.
140179
141-
Alternatively, you can install your package using `pip install -e . --no-deps` to only install the package. And install the rest of your depenedncies using a conda environment file.
180+
Alternatively, you can install your package using `pip install -e . --no-deps` to only install the package. And install the rest of your dependencies using a conda environment file.
142181
```

package-structure-code/intro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Intro <self>
156156
Python package structure <python-package-structure>
157157
pyproject.toml Package Metadata <pyproject-toml-python-package-metadata>
158158
Build Your Package <python-package-distribution-files-sdist-wheel>
159+
Declare dependencies <declare-dependencies>
159160
Package Build Tools <python-package-build-tools>
160161
Complex Builds <complex-python-package-builds>
161162
```

0 commit comments

Comments
 (0)