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

45 lines
1.2 KiB
YAML

- name: Install pip
include_role:
name: ensure-pip
- name: Check if uv is installed
shell: |
command -v {{ ensure_uv_executable }} {{ ensure_uv_venv_path }}/bin/uv || exit 1
args:
executable: /bin/bash
register: uv_preinstalled
failed_when: false
- name: Export preinstalled ensure_uv_executable
set_fact:
ensure_uv_executable: "{{ uv_preinstalled.stdout_lines[0] }}"
cacheable: true
when: uv_preinstalled.rc == 0
- name: Install uv to local env
when: uv_preinstalled.rc != 0
block:
- name: Create local venv
command: "{{ ensure_pip_virtualenv_command }} {{ ensure_uv_venv_path }}"
- name: Install uv to local venv
command: "{{ ensure_uv_venv_path }}/bin/pip install uv{{ ensure_uv_version }}"
- name: Export installed ensure_uv_executable path
set_fact:
ensure_uv_executable: "{{ ensure_uv_venv_path }}/bin/uv"
cacheable: true
- name: Output uv version
command: "{{ ensure_uv_executable }} --version"
- name: Make global symlink
when:
- ensure_uv_global_symlink
- ensure_uv_executable != '/usr/local/bin/uv'
file:
state: link
src: "{{ ensure_uv_executable }}"
dest: /usr/local/bin/uv
become: yes