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
This commit is contained in:
Mohammed Naser 2020-03-03 11:55:45 -05:00 committed by Andreas Jaeger
parent 6f491cba6c
commit 9254fbb5ff
3 changed files with 25 additions and 1 deletions

View File

@ -2,3 +2,18 @@ Ensure tox is installed
If tox is not already installed, it will be installed via pip in the If tox is not already installed, it will be installed via pip in the
user install directory (i.e., "pip install --user"). 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.

View File

@ -1 +1,2 @@
tox_executable: tox tox_executable: tox
tox_prefer_python2: true

View File

@ -2,11 +2,19 @@
shell: | shell: |
set -euo pipefail set -euo pipefail
{% if tox_prefer_python2 %}
if command -v pip; then if command -v pip; then
PIP=pip PIP=pip
elif command -v pip3; then elif command -v pip3; then
PIP=pip3 PIP=pip3
fi fi
{% else %}
if command -v pip3; then
PIP=pip3
elif command -v pip; then
PIP=pip
fi
{% endif %}
type tox || $PIP install --user tox type tox || $PIP install --user tox
args: args: