|
1 | | -import os |
2 | | -import shutil |
3 | 1 | import subprocess |
4 | 2 | import sys |
5 | | -from glob import glob |
6 | 3 |
|
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') |
9 | 14 |
|
10 | 15 |
|
11 | 16 | 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) |
29 | 22 |
|
30 | 23 |
|
31 | 24 | if __name__ == '__main__': |
|
0 commit comments