524b7e7b95
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
45 lines
1.3 KiB
YAML
45 lines
1.3 KiB
YAML
- name: Install pip
|
|
include_role:
|
|
name: ensure-pip
|
|
|
|
- name: Check if poetry is installed
|
|
shell: |
|
|
command -v {{ ensure_poetry_executable }} {{ ensure_poetry_venv_path }}/bin/poetry || exit 1
|
|
args:
|
|
executable: /bin/bash
|
|
register: poetry_preinstalled
|
|
failed_when: false
|
|
|
|
- name: Export preinstalled ensure_poetry_executable
|
|
set_fact:
|
|
ensure_poetry_executable: "{{ poetry_preinstalled.stdout_lines[0] }}"
|
|
cacheable: true
|
|
when: poetry_preinstalled.rc == 0
|
|
|
|
- name: Install poetry to local env
|
|
when: poetry_preinstalled.rc != 0
|
|
block:
|
|
- name: Create local venv
|
|
command: "{{ ensure_pip_virtualenv_command }} {{ ensure_poetry_venv_path }}"
|
|
|
|
- name: Install poetry to local venv
|
|
command: "{{ ensure_poetry_venv_path }}/bin/pip install poetry{{ ensure_poetry_version }}"
|
|
|
|
- name: Export installed ensure_poetry_executable path
|
|
set_fact:
|
|
ensure_poetry_executable: "{{ ensure_poetry_venv_path }}/bin/poetry"
|
|
cacheable: true
|
|
|
|
- name: Output poetry version
|
|
command: "{{ ensure_poetry_executable }} --version"
|
|
|
|
- name: Make global symlink
|
|
when:
|
|
- ensure_poetry_global_symlink
|
|
- ensure_poetry_executable != '/usr/local/bin/poetry'
|
|
file:
|
|
state: link
|
|
src: "{{ ensure_poetry_executable }}"
|
|
dest: /usr/local/bin/poetry
|
|
become: yes
|