Aurelio Jargas 506e7a9025 Add ensure-uv role
Uv (https://docs.astral.sh/uv/) 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_uv_version` is
  informed.

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

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

This new role is a verbatim copy of the `ensure-poetry` role, just doing
a `s/poetry/uv/g`. Even this commit is a replay of the commit adding
that role: 524b7e7b95dcd6adc311e74dd7f0e6da8a3cce58.

Change-Id: I55bc5e1d273045d0978b09f719bf79a875336e30
2025-01-27 21:42:14 +01:00

43 lines
1.3 KiB
ReStructuredText

Ensure uv is installed
Look for ``uv``, and if not found, install it via ``pip`` into a
virtual environment for the current user.
**Role Variables**
.. zuul:rolevar:: ensure_uv_version
:default: ''
Version specifier to select the version of uv. The default is the
latest version.
.. zuul:rolevar:: ensure_uv_venv_path
:default: {{ ansible_user_dir }}/.local/uv
Directory for the Python venv where uv will be installed.
.. zuul:rolevar:: ensure_uv_global_symlink
:default: False
Install a symlink to the uv executable into ``/usr/local/bin/uv``.
This can be useful when scripts need to be run that expect to find
uv in a more standard location and plumbing through the value
of ``ensure_uv_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_uv_executable
:default: uv
After running this role, ``ensure_uv_executable`` will be set as the path
to a valid ``uv``.
At role runtime, look for an existing ``uv`` at this specific
path. Note the default (``uv``) effectively means to find uv in
the current ``$PATH``. For example, if your base image
pre-installs uv in an out-of-path environment, set this so the
role does not attempt to install the user version.