Skip to content
Guillaume Dumas edited this page Jul 20, 2023 · 7 revisions

Introduction to Poetry

Presentation

Poetry is a Python packaging and dependency management tool very easy to use.

Is is highly recommended to use while developing for HyPyP.

Installation

Poetry can be installed on any OS (https://python-poetry.org/docs/#installation)

Once installed, open a shell on your local HyPyP Git directory and type the following:

poetry install

It creates a Python virtual environment dedicated to the project and install all the required libraries within this environment.

Managing dependencies

If you want to add a library to the project, do not use pip but type :

poetry add your_lib_name

If this is a dependency required only for documentation, test or development help (linter, formatter ...) type the following :

poetry add --group dev your_lib_name

To remove a dependency, just type :

poetry remove your_lib_name

To update all packages to the last compatible version :

poetry update

The pyproject.toml configuration file

On the root of the git folder, there is a pyproject.toml configuration file for this poetry project. It contains all the requirements information but it's not recommended to use it for add or remove package and rather use the poetry addand poetry remove commands.

The more important with this file is information for PyPi packaging. For more information : https://python-poetry.org/docs/pyproject/.

Publish on PyPi

Here comes the magic ;-) Once your ready to publish on PyPi a new version with a pyproject.toml ready, just type :

poetry build
poetry publish

Warning: it is now recommended to use API tokens. More info: "How To Publish Python Packages to PyPI using Poetry"

Update docs requirements

To update the doc on readthedocs, you must run with bash the script update_docs_requirements.sh.

Note: to test doc generation python -m mkdocs build --clean --site-dir _build/html --config-file mkdocs.yml and to test locally with a webserver python -m mkdocs serve

Full documentation

If you want to dive more on poetry usage, check the documentation : https://python-poetry.org/docs/