Skip to content

Commit d1bf0d2

Browse files
authored
Merge pull request #1962 from pypa/debt/pip-version
Rely on tox-pip-version to upgrade pip
2 parents 70b3ec0 + 6cb025e commit d1bf0d2

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

tools/tox_pip.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
1-
import os
2-
import shutil
31
import subprocess
42
import sys
5-
from glob import glob
63

7-
VIRTUAL_ENV = os.environ['VIRTUAL_ENV']
8-
TOX_PIP_DIR = os.path.join(VIRTUAL_ENV, 'pip')
4+
5+
def remove_setuptools():
6+
"""
7+
Remove setuptools from the current environment.
8+
"""
9+
print("Removing setuptools")
10+
cmd = [sys.executable, '-m', 'pip', 'uninstall', '-y', 'setuptools']
11+
# set cwd to something other than '.' to avoid detecting
12+
# '.' as the installed package.
13+
subprocess.check_call(cmd, cwd='.tox')
914

1015

1116
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-
# Fix call for setuptools editable install.
25-
for n, a in enumerate(args):
26-
if a == '.':
27-
args[n] = os.getcwd()
28-
subprocess.check_call([sys.executable, '-m', 'pip'] + args, cwd=TOX_PIP_DIR)
17+
# When installing '.', remove setuptools
18+
'.' in args and remove_setuptools()
19+
20+
cmd = [sys.executable, '-m', 'pip'] + args
21+
subprocess.check_call(cmd)
2922

3023

3124
if __name__ == '__main__':

tox.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
[tox]
88
envlist=python
9+
minversion = 3.2
10+
requires =
11+
tox-pip-version >= 0.0.6
912

1013
[helpers]
11-
# Wrapper for calls to pip that make sure the version being used is a
12-
# up-to-date, and to prevent the current working directory from being
13-
# added to `sys.path`.
14+
# Custom pip behavior
1415
pip = python {toxinidir}/tools/tox_pip.py
1516

1617
[testenv]
1718
deps=-r{toxinidir}/tests/requirements.txt
19+
pip_version = pip
1820
install_command = {[helpers]pip} install {opts} {packages}
1921
list_dependencies_command = {[helpers]pip} freeze --all
2022
setenv=COVERAGE_FILE={toxworkdir}/.coverage.{envname}

0 commit comments

Comments
 (0)