diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-02-04 05:34:30 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-04 05:34:30 -0500 |
| commit | 54b76e63bb7ace4cd1be29d75f6dcfe3227444f9 (patch) | |
| tree | 50fce6e6ca78d05287df8f8f600029d554eb0a26 /tools | |
| parent | 73376585065bbf28395c71fe15137c19a712d4f3 (diff) | |
| parent | 91ede46d247291a5e5449403880c15a2674ebcb5 (diff) | |
| download | external_python_setuptools-54b76e63bb7ace4cd1be29d75f6dcfe3227444f9.tar.gz external_python_setuptools-54b76e63bb7ace4cd1be29d75f6dcfe3227444f9.tar.bz2 external_python_setuptools-54b76e63bb7ace4cd1be29d75f6dcfe3227444f9.zip | |
Merge pull request #1981 from pypa/feature/deps-in-metadata
Move test dependencies to package metadata.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/tox_pip.py | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/tools/tox_pip.py b/tools/tox_pip.py index 2d33e9e5..9fe4f905 100644 --- a/tools/tox_pip.py +++ b/tools/tox_pip.py @@ -1,6 +1,7 @@ import os import subprocess import sys +import re def remove_setuptools(): @@ -20,18 +21,62 @@ def bootstrap(): subprocess.check_call(cmd) -def pip(args): - # Honor requires-python when installing test suite dependencies - if any('-r' in arg for arg in args): - os.environ['PIP_IGNORE_REQUIRES_PYTHON'] = '0' +def is_install_self(args): + """ + Do the args represent an install of .? + """ + def strip_extras(arg): + match = re.match(r'(.*)?\[.*\]$', arg) + return match.group(1) if match else arg + + return ( + 'install' in args + and any( + arg in ['.', os.getcwd()] + for arg in map(strip_extras, args) + ) + ) + + +def pip(*args): + cmd = [sys.executable, '-m', 'pip'] + list(args) + return subprocess.check_call(cmd) + + +def test_dependencies(): + from ConfigParser import ConfigParser + + def clean(dep): + spec, _, _ = dep.partition('#') + return spec.strip() - if '.' in args: + parser = ConfigParser() + parser.read('setup.cfg') + raw = parser.get('options.extras_require', 'tests').split('\n') + return filter(None, map(clean, raw)) + + +def disable_python_requires(): + """ + On Python 2, install the dependencies that are selective + on Python version while honoring REQUIRES_PYTHON, then + disable REQUIRES_PYTHON so that pip can install this + checkout of setuptools. + """ + pip('install', *test_dependencies()) + os.environ['PIP_IGNORE_REQUIRES_PYTHON'] = 'true' + + +def run(args): + os.environ['PIP_USE_PEP517'] = 'true' + + if is_install_self(args): remove_setuptools() bootstrap() + sys.version_info > (3,) or disable_python_requires() - cmd = [sys.executable, '-m', 'pip'] + args - subprocess.check_call(cmd) + pip(*args) if __name__ == '__main__': - pip(sys.argv[1:]) + run(sys.argv[1:]) |
