diff options
Diffstat (limited to 'tools/tox_pip.py')
| -rw-r--r-- | tools/tox_pip.py | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/tools/tox_pip.py b/tools/tox_pip.py index 5aeca805..2d33e9e5 100644 --- a/tools/tox_pip.py +++ b/tools/tox_pip.py @@ -1,37 +1,36 @@ 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 remove_setuptools(): + """ + Remove setuptools from the current environment. + """ + print("Removing setuptools") + cmd = [sys.executable, '-m', 'pip', 'uninstall', '-y', 'setuptools'] + # set cwd to something other than '.' to avoid detecting + # '.' as the installed package. + subprocess.check_call(cmd, cwd='.tox') + + +def bootstrap(): + print("Running bootstrap") + cmd = [sys.executable, '-m', 'bootstrap'] + subprocess.check_call(cmd) 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) - # Disable PEP 517 support when using editable installs. - for n, a in enumerate(args): - if not a.startswith('-'): - if a in 'install' and '-e' in args[n:]: - args.insert(n + 1, '--no-use-pep517') - break - # Fix call for setuptools editable install. - for n, a in enumerate(args): - if a == '.': - args[n] = os.getcwd() - subprocess.check_call([sys.executable, '-m', 'pip'] + args, cwd=TOX_PIP_DIR) + # Honor requires-python when installing test suite dependencies + if any('-r' in arg for arg in args): + os.environ['PIP_IGNORE_REQUIRES_PYTHON'] = '0' + + if '.' in args: + remove_setuptools() + bootstrap() + + cmd = [sys.executable, '-m', 'pip'] + args + subprocess.check_call(cmd) if __name__ == '__main__': |
