Skip to content

Commit 541ec23

Browse files
authored
Merge pull request #5843 from benoit-pierre/fix_tox.ini_install_command
tox: fix environment setup
2 parents 817dfcb + c9e47c9 commit 541ec23

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

tools/tox_pip.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import sys
5+
from glob import glob
6+
7+
VIRTUAL_ENV = os.environ['VIRTUAL_ENV']
8+
TOX_PIP_DIR = os.path.join(VIRTUAL_ENV, 'pip')
9+
10+
11+
def pip(args):
12+
# First things first, get a recent (stable) version of pip.
13+
if not os.path.exists(TOX_PIP_DIR):
14+
subprocess.check_call([sys.executable, '-m', 'pip',
15+
'--disable-pip-version-check',
16+
'install', '-t', TOX_PIP_DIR,
17+
'pip'])
18+
shutil.rmtree(glob(os.path.join(TOX_PIP_DIR, 'pip-*.dist-info'))[0])
19+
# And use that version.
20+
pypath = os.environ.get('PYTHONPATH')
21+
pypath = pypath.split(os.pathsep) if pypath is not None else []
22+
pypath.insert(0, TOX_PIP_DIR)
23+
os.environ['PYTHONPATH'] = os.pathsep.join(pypath)
24+
subprocess.check_call([sys.executable, '-m', 'pip'] + args)
25+
26+
27+
if __name__ == '__main__':
28+
pip(sys.argv[1:])

tox.ini

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ envlist =
33
docs, packaging, lint-py2, lint-py3, mypy,
44
py27, py34, py35, py36, py37, py38, pypy, pypy3
55

6+
[helpers]
7+
# Wrapper for calls to pip that make sure the version being used is the
8+
# original virtualenv (stable) version, and not the code being tested.
9+
pip = python {toxinidir}/tools/tox_pip.py
10+
611
[testenv]
712
passenv = CI GIT_SSL_CAINFO
813
setenv =
@@ -11,7 +16,8 @@ setenv =
1116
LC_CTYPE = en_US.UTF-8
1217
deps = -r{toxinidir}/tools/tests-requirements.txt
1318
commands = pytest --timeout 300 []
14-
install_command = python -m pip install {opts} {packages}
19+
install_command = {[helpers]pip} install {opts} {packages}
20+
list_dependencies_command = {[helpers]pip} freeze --all
1521
usedevelop = True
1622

1723
[testenv:coverage-py3]

0 commit comments

Comments
 (0)