Skip to content

Commit

Permalink
Merge pull request #255 from staticdev/bugfix/install-pipx-without-pip
Browse files Browse the repository at this point in the history
Fix pipx install for Debian 12
  • Loading branch information
staticdev authored Jul 10, 2023
2 parents 2b96f3f + f247337 commit 489fa91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ galaxy_info:
- pyenv
- pipx
- precommit
- tox
- workstation

dependencies:
Expand Down
4 changes: 4 additions & 0 deletions tasks/custom_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Set command path based on distribution
ansible.builtin.set_fact:
pipx_path: "{{ '/usr/bin' if ansible_distribution_release == 'bookworm' else ansible_env.HOME + '/.local/bin' }}"
25 changes: 17 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
- name: Load custom facts
ansible.builtin.import_tasks: custom_facts.yml

- name: Install pyenv
ansible.builtin.import_role:
name: staticdev.pyenv
Expand All @@ -17,16 +20,21 @@
- python3-venv # needed for nox

- name: Check if pipx is installed
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx --version"
ansible.builtin.command: "{{ pipx_path }}/pipx --version"
register: pipx_version_cmd
changed_when: false
ignore_errors: true

- name: Install pipx
- name: Install pipx on Debian Bookworm
ansible.builtin.package:
name: pipx
when: pipx_version_cmd is failed and ansible_distribution_release == 'bookworm'

- name: Install pipx on non-Bookworm OS
ansible.builtin.pip:
name: pipx
extra_args: --user
when: pipx_version_cmd is failed
when: pipx_version_cmd is failed and ansible_distribution_release != 'bookworm'

- name: Check if pre-commit is installed
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pre-commit --version"
Expand All @@ -35,7 +43,7 @@
ignore_errors: true

- name: Install pre-commit
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install pre-commit"
ansible.builtin.command: "{{ pipx_path }}/pipx install pre-commit"
register: output
changed_when: "output.rc == 0"
when: pre_commit_check is failed
Expand All @@ -44,9 +52,10 @@
ansible.builtin.stat:
path: "{{ ansible_env.HOME }}/.local/pipx/venvs/cookiecutter"
register: cookiecutter_folder_check
ignore_errors: true

- name: Install cookiecutter
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install cookiecutter"
ansible.builtin.command: "{{ pipx_path }}/pipx install cookiecutter"
register: output
changed_when: "output.rc == 0"
when: cookiecutter_folder_check is failed
Expand Down Expand Up @@ -79,13 +88,13 @@
ignore_errors: true

- name: Install nox
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install nox"
ansible.builtin.command: "{{ pipx_path }}/pipx install nox"
register: output
changed_when: "output.rc == 0"
when: nox_version_cmd is failed

- name: Install nox-poetry
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx inject nox nox-poetry"
ansible.builtin.command: "{{ pipx_path }}/pipx inject nox nox-poetry"
register: output
changed_when: "output.rc == 0"
when: nox_version_cmd is failed
Expand All @@ -97,7 +106,7 @@
ignore_errors: true

- name: Install tox
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install tox"
ansible.builtin.command: "{{ pipx_path }}/pipx install tox"
register: output
changed_when: "output.rc == 0"
when: tox_version_cmd is failed

0 comments on commit 489fa91

Please sign in to comment.