Revert "Revert "ensure-tox: use venv to install""

This reverts commit bac2bf6c45.

The problem was really that ensure-pip was giving us a
"ensure_pip_virtualenv_command" that didn't work on some systems.
Iaa3ecd05b64af6dd9b2ee17a39bcbe6cde8686ba fixes this underlying issue,
so we can revert to the original change that uses that to install the
tox environment.

Change-Id: I8ce9dceb721474d3220f6e72409481dc89875ee0
This commit is contained in:
Ian Wienand 2020-05-11 10:23:04 +10:00
parent bbb149ebf9
commit 9c04709719
4 changed files with 24 additions and 31 deletions

View File

@ -1,7 +1,7 @@
Ensure tox is installed Ensure tox is installed
Look for ``tox``, and if not found, install it via ``pip`` in the user Look for ``tox``, and if not found, install it via ``pip`` into a
install directory (i.e., ``pip install --user``). virtual environment for the current user.
**Role Variables** **Role Variables**

View File

@ -1,2 +1,3 @@
tox_executable: tox tox_executable: tox
tox_venv_path: '{{ ansible_user_dir }}/.local/tox'
tox_prefer_python2: false tox_prefer_python2: false

View File

@ -4,41 +4,33 @@
vars: vars:
ensure_pip_from_packages_with_python2: '{{ tox_prefer_python2 }}' ensure_pip_from_packages_with_python2: '{{ tox_prefer_python2 }}'
- name: Ensure tox is installed - name: Check if tox is installed
shell: | shell: |
set -euo pipefail command -v {{ tox_executable }} || exit 1
{% if tox_prefer_python2 %}
if command -v pip; then
PIP=pip
elif command -v pip3; then
PIP=pip3
fi
{% else %}
if command -v pip3; then
PIP=pip3
elif command -v pip; then
PIP=pip
fi
{% endif %}
type {{ tox_executable }} || $PIP install --user tox
args: args:
executable: /bin/bash executable: /bin/bash
register: result register: tox_preinstalled
changed_when: "'Successfully installed' in result.stdout" failed_when: false
- name: Set tox_executable fact to pip installed - name: Export preinstalled tox_exectuable
set_fact: set_fact:
tox_executable: "{{ ansible_user_dir }}/.local/bin/tox" tox_executable: '{{ tox_executable }}'
cacheable: true cacheable: true
when: result is changed when: tox_preinstalled.rc == 0
- name: Set tox_exectuable fact to found tox - name: Install tox to local env
set_fact: when: tox_preinstalled.rc != 0
tox_executable: "{{ tox_executable }}" block:
cacheable: true - name: Install tox to local venv
when: result is not changed pip:
name: tox
virtualenv_command: '{{ ensure_pip_virtualenv_command }}'
virtualenv: '{{ tox_venv_path }}'
- name: Export installed tox_executable path
set_fact:
tox_executable: '{{ tox_venv_path }}/bin/tox'
cacheable: true
- name: Output tox version - name: Output tox version
command: "{{ tox_executable }} --version" command: "{{ tox_executable }} --version"

View File

@ -27,7 +27,7 @@
- name: Verify tox_executable is set - name: Verify tox_executable is set
assert: assert:
that: that:
- tox_executable == "{{ ansible_user_dir }}/.local/bin/tox" - tox_executable == "{{ ansible_user_dir }}/.local/tox/bin/tox"
- name: Verify tox is installed - name: Verify tox is installed
command: "{{ tox_executable }} --version" command: "{{ tox_executable }} --version"
register: result register: result