diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-02-11 22:15:31 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-02-11 22:15:31 -0500 |
| commit | ce8e3ee174ed9dee84aa08a461fb174ac1e53535 (patch) | |
| tree | da78c024b4491210e61b73e9e2f755d46c8bc1ff /tools/tox_pip.py | |
| parent | 53b8523fdfa19173d2e6b11d6b4d175f54b9dfea (diff) | |
| parent | a5dec2f14e3414e4ee5dd146bff9c289d573de9a (diff) | |
| download | python-setuptools-git-ce8e3ee174ed9dee84aa08a461fb174ac1e53535.tar.gz | |
Merge branch 'master' into fix/1557
Diffstat (limited to 'tools/tox_pip.py')
| -rw-r--r-- | tools/tox_pip.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tools/tox_pip.py b/tools/tox_pip.py new file mode 100644 index 00000000..9fe4f905 --- /dev/null +++ b/tools/tox_pip.py @@ -0,0 +1,82 @@ +import os +import subprocess +import sys +import re + + +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 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() + + 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() + + pip(*args) + + +if __name__ == '__main__': + run(sys.argv[1:]) |
