Skip to content

Commit

Permalink
Merge pull request #5843 from benoit-pierre/fix_tox.ini_install_command
Browse files Browse the repository at this point in the history
tox: fix environment setup
  • Loading branch information
pradyunsg committed Oct 10, 2018
2 parents 817dfcb + c9e47c9 commit 541ec23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tools/tox_pip.py
Original file line number Diff line number Diff line change
@@ -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:])
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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]
Expand Down

0 comments on commit 541ec23

Please sign in to comment.