Skip to content

Add guide on Poetry #8702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guides/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ or customize the documentation appearance.
reproducible-builds
embedding-content
conda
poetry
remove-edit-buttons
build-using-too-many-resources
edit-source-links-sphinx
67 changes: 67 additions & 0 deletions docs/guides/poetry.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Specifying your dependencies with Poetry
========================================

Declaring your project metadata
-------------------------------

Poetry is a :pep:`517`-compliant build backend, which means that
`it generates your project
metadata <https://python-poetry.org/docs/pyproject/#poetry-and-pep-517>`_
using a standardized interface that can be consumed directly by pip.
Therefore, by making sure that
the ``build-system`` section of your ``pyproject.toml``
declares the build backend as follows:

.. code-block:: toml
:caption: pyproject.toml

[build-system]
requires = ["poetry_core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

You will be able to install it on Read the Docs just using pip,
using a configuration like this:

.. code-block:: yaml
:caption: .readthedocs.yaml
:emphasize-lines: 8-11

version: 2

build:
os: ubuntu-20.04
tools:
python: "3.9"

python:
install:
- method: pip
path: .

For example, the `rich <https://rich.readthedocs.io/>`_ Python library
`uses Poetry <https://github.com/willmcgugan/rich/blob/ba5d0c2c/pyproject.toml#L49-L51>`_
to declare its library dependencies
and installs itself on Read the Docs
`with pip <https://github.com/willmcgugan/rich/blob/ba5d0c2c/.readthedocs.yml#L18-L19>`_.

Locking your dependencies
-------------------------

With you ``pyproject.toml`` file you are free to `specify the dependency
versions <https://python-poetry.org/docs/dependency-specification/>`_
that are more appropriate for your project,
either by leaving them unpinned or setting some constraints.
However, to achieve :doc:`/guides/reproducible-builds`
it is better that you lock your dependencies,
so that the decision to upgrade any of them is yours.
Poetry does this using ``poetry.lock`` files
that contain the exact versions of all your transitive dependencies
(that is, all the dependencies of your dependencies).

The first time you run ``poetry install`` in your project directory
`Poetry will generate a new poetry.lock
file <https://python-poetry.org/docs/basic-usage/#installing-without-poetrylock>`_
with the versions available at that moment.
You can then `commit your poetry.lock to version
control <https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control>`_
so that Read the Docs also uses these exact dependencies.