diff --git a/roles/ensure-tox/README.rst b/roles/ensure-tox/README.rst index 60e0cac34..31a7a4a53 100644 --- a/roles/ensure-tox/README.rst +++ b/roles/ensure-tox/README.rst @@ -2,3 +2,18 @@ Ensure tox is installed If tox is not already installed, it will be installed via pip in the user install directory (i.e., "pip install --user"). + +**Role Variables** + +.. zuul:rolevar:: tox_executable + :default: ``tox`` + + Optional path to point tox executable + +.. zuul:rolevar:: tox_prefer_python2 + :default: ``true`` + + If tox is not detected, prefer to install tox inside Python 2 instead of + Python 3. The default value is currently set to ``true`` for compatibility + reasons, it will be switched to false eventually. It's best to set this to + ``false`` when using it. diff --git a/roles/ensure-tox/defaults/main.yml b/roles/ensure-tox/defaults/main.yml index 35e4a9af6..36efbb49a 100644 --- a/roles/ensure-tox/defaults/main.yml +++ b/roles/ensure-tox/defaults/main.yml @@ -1 +1,2 @@ -tox_executable: tox \ No newline at end of file +tox_executable: tox +tox_prefer_python2: true diff --git a/roles/ensure-tox/tasks/main.yaml b/roles/ensure-tox/tasks/main.yaml index 55cd0b585..ec44cc1d6 100644 --- a/roles/ensure-tox/tasks/main.yaml +++ b/roles/ensure-tox/tasks/main.yaml @@ -2,11 +2,19 @@ shell: | set -euo pipefail + {% 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 || $PIP install --user tox args: