zuul-jobs/roles/ensure-poetry/README.rst
Aurelio Jargas 524b7e7b95 Add ensure-poetry role
Poetry (https://python-poetry.org) is not declared as a dependency for a
Python project, it must be available somehow in the system. This role
installs it if missing.

- Latest version is installed, unless `ensure_poetry_version` is
  informed.

- The installed executable path is set as the `poetry_executable` fact.

- The `/usr/local/bin/poetry` symlink can also be created if
  `ensure_poetry_global_symlink: true`.

This new role is basically a copy of the `ensure-nox` role with the
symlink creation snippet taken from the `ensure-tox` role.

The commit adding `ensure-nox` (77b1b24) has been taken as an example of
the necessary changes when adding a new role.

Change-Id: I5592d38d415a9d74055348406653b69f110541ae
2024-07-02 08:00:55 -07:00

43 lines
1.4 KiB
ReStructuredText

Ensure Poetry is installed
Look for ``poetry``, and if not found, install it via ``pip`` into a
virtual environment for the current user.
**Role Variables**
.. zuul:rolevar:: ensure_poetry_version
:default: ''
Version specifier to select the version of Poetry. The default is the
latest version.
.. zuul:rolevar:: ensure_poetry_venv_path
:default: {{ ansible_user_dir }}/.local/poetry
Directory for the Python venv where Poetry will be installed.
.. zuul:rolevar:: ensure_poetry_global_symlink
:default: False
Install a symlink to the poetry executable into ``/usr/local/bin/poetry``.
This can be useful when scripts need to be run that expect to find
Poetry in a more standard location and plumbing through the value
of ``ensure_poetry_executable`` would be onerous.
Setting this requires root access, so should only be done in
circumstances where root access is available.
**Output Variables**
.. zuul:rolevar:: ensure_poetry_executable
:default: poetry
After running this role, ``ensure_poetry_executable`` will be set as the path
to a valid ``poetry``.
At role runtime, look for an existing ``poetry`` at this specific
path. Note the default (``poetry``) effectively means to find poetry in
the current ``$PATH``. For example, if your base image
pre-installs poetry in an out-of-path environment, set this so the
role does not attempt to install the user version.