From 9254fbb5ffc885b89cd566199851e618804a86c7 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Tue, 3 Mar 2020 11:55:45 -0500 Subject: [PATCH] ensure-tox: add prefer_python2 This patch enables the ability to set a value which prefers the installation of tox within python2 over python3. Change-Id: I29c9585aa9048c0e2855ec1eaf1f48041cfe46e2 --- roles/ensure-tox/README.rst | 15 +++++++++++++++ roles/ensure-tox/defaults/main.yml | 3 ++- roles/ensure-tox/tasks/main.yaml | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) 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: