Skip to content

Commit ecda33f

Browse files
authored
Merge pull request #8702 from readthedocs/poetry-guide
Add guide on Poetry
2 parents 694f8cc + cf82e08 commit ecda33f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

docs/guides/developers.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ or customize the documentation appearance.
1414
reproducible-builds
1515
embedding-content
1616
conda
17+
poetry
1718
remove-edit-buttons
1819
build-using-too-many-resources
1920
edit-source-links-sphinx

docs/guides/poetry.rst

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Specifying your dependencies with Poetry
2+
========================================
3+
4+
Declaring your project metadata
5+
-------------------------------
6+
7+
Poetry is a :pep:`517`-compliant build backend, which means that
8+
`it can generate your project
9+
metadata <https://python-poetry.org/docs/pyproject/#poetry-and-pep-517>`_
10+
using a standardized interface that can be consumed directly by pip.
11+
To do that, first make sure that
12+
the ``build-system`` section of your ``pyproject.toml``
13+
declares the build backend as follows:
14+
15+
.. code-block:: toml
16+
:caption: pyproject.toml
17+
18+
[build-system]
19+
requires = ["poetry_core>=1.0.0"]
20+
build-backend = "poetry.core.masonry.api"
21+
22+
Then, you will be able to install it on Read the Docs just using pip,
23+
with a configuration like this:
24+
25+
.. code-block:: yaml
26+
:caption: .readthedocs.yaml
27+
:emphasize-lines: 8-11
28+
29+
version: 2
30+
31+
build:
32+
os: ubuntu-20.04
33+
tools:
34+
python: "3.9"
35+
36+
python:
37+
install:
38+
- method: pip
39+
path: .
40+
41+
For example, the `rich <https://rich.readthedocs.io/>`_ Python library
42+
`uses Poetry <https://github.com/willmcgugan/rich/blob/ba5d0c2c/pyproject.toml#L49-L51>`_
43+
to declare its library dependencies
44+
and installs itself on Read the Docs
45+
`with pip <https://github.com/willmcgugan/rich/blob/ba5d0c2c/.readthedocs.yml#L18-L19>`_.
46+
47+
Locking your dependencies
48+
-------------------------
49+
50+
With your ``pyproject.toml`` file you are free to `specify the dependency
51+
versions <https://python-poetry.org/docs/dependency-specification/>`_
52+
that are most appropriate for your project,
53+
either by leaving them unpinned or setting some constraints.
54+
However, to achieve :doc:`/guides/reproducible-builds`
55+
it is better that you lock your dependencies,
56+
so that the decision to upgrade any of them is yours.
57+
Poetry does this using ``poetry.lock`` files
58+
that contain the exact versions of all your transitive dependencies
59+
(that is, all the dependencies of your dependencies).
60+
61+
The first time you run ``poetry install`` in your project directory
62+
`Poetry will generate a new poetry.lock
63+
file <https://python-poetry.org/docs/basic-usage/#installing-without-poetrylock>`_
64+
with the versions available at that moment.
65+
You can then `commit your poetry.lock to version
66+
control <https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control>`_
67+
so that Read the Docs also uses these exact dependencies.

0 commit comments

Comments
 (0)