From c9e47c9903b1e1a6e2f0d7d59eb1592bce755324 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 1 Oct 2018 05:22:08 +0200 Subject: [PATCH] tox: fix environment setup Ensure a stable version of pip is used for installing dependencies, and not the version about to be tested. --- tools/tox_pip.py | 28 ++++++++++++++++++++++++++++ tox.ini | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tools/tox_pip.py diff --git a/tools/tox_pip.py b/tools/tox_pip.py new file mode 100644 index 000000000..8d91fbf56 --- /dev/null +++ b/tools/tox_pip.py @@ -0,0 +1,28 @@ +import os +import shutil +import subprocess +import sys +from glob import glob + +VIRTUAL_ENV = os.environ['VIRTUAL_ENV'] +TOX_PIP_DIR = os.path.join(VIRTUAL_ENV, 'pip') + + +def pip(args): + # First things first, get a recent (stable) version of pip. + if not os.path.exists(TOX_PIP_DIR): + subprocess.check_call([sys.executable, '-m', 'pip', + '--disable-pip-version-check', + 'install', '-t', TOX_PIP_DIR, + 'pip']) + shutil.rmtree(glob(os.path.join(TOX_PIP_DIR, 'pip-*.dist-info'))[0]) + # And use that version. + pypath = os.environ.get('PYTHONPATH') + pypath = pypath.split(os.pathsep) if pypath is not None else [] + pypath.insert(0, TOX_PIP_DIR) + os.environ['PYTHONPATH'] = os.pathsep.join(pypath) + subprocess.check_call([sys.executable, '-m', 'pip'] + args) + + +if __name__ == '__main__': + pip(sys.argv[1:]) diff --git a/tox.ini b/tox.ini index 4a3272955..c48d695de 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,11 @@ envlist = docs, packaging, lint-py2, lint-py3, mypy, py27, py34, py35, py36, py37, py38, pypy, pypy3 +[helpers] +# Wrapper for calls to pip that make sure the version being used is the +# original virtualenv (stable) version, and not the code being tested. +pip = python {toxinidir}/tools/tox_pip.py + [testenv] passenv = CI GIT_SSL_CAINFO setenv = @@ -11,7 +16,8 @@ setenv = LC_CTYPE = en_US.UTF-8 deps = -r{toxinidir}/tools/tests-requirements.txt commands = pytest --timeout 300 [] -install_command = python -m pip install {opts} {packages} +install_command = {[helpers]pip} install {opts} {packages} +list_dependencies_command = {[helpers]pip} freeze --all usedevelop = True [testenv:coverage-py3]