Jeremy Stanley 087406800d Add ensure-pyproject-build role
pyproject-build (https://build.pypa.io/) is used as a pyproject (PEP
517) build frontend. This role installs it if missing.

This new role is basically a copy of the `ensure-poetry` role, in
turn copied from other roles in this repository.

Change-Id: If6e3970d995256beea170cad039d7dba9538d191
2025-01-27 19:56:21 +00:00

45 lines
1.5 KiB
YAML

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