-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add guide on Poetry #8702
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. 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>`_. | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Locking your dependencies | ||
------------------------- | ||
|
||
With you ``pyproject.toml`` file you are free to `specify the dependency | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
versions <https://python-poetry.org/docs/dependency-specification/>`_ | ||
that are more appropriate for your project, | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.