aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-01-20 10:34:25 -0500
committerJason R. Coombs <jaraco@jaraco.com>2020-01-20 10:37:57 -0500
commitd92f778b6c88c8a36c4aecac9543d9297c425096 (patch)
treef49bb90de25cc9625d1f97fa8c67ba32accd12cb
parent6d4e23882a5b1e1f31fb452aaad9d19cf0d02604 (diff)
downloadexternal_python_setuptools-d92f778b6c88c8a36c4aecac9543d9297c425096.tar.gz
external_python_setuptools-d92f778b6c88c8a36c4aecac9543d9297c425096.tar.bz2
external_python_setuptools-d92f778b6c88c8a36c4aecac9543d9297c425096.zip
Rewrite selective PIP_IGNORE_REQUIRES_PYTHON to allow test dependencies in metadata to be installed without ignoring REQUIRES_PYTHON
-rw-r--r--setuptools/tests/test_virtualenv.py11
-rw-r--r--tools/tox_pip.py39
-rw-r--r--tox.ini1
3 files changed, 43 insertions, 8 deletions
diff --git a/setuptools/tests/test_virtualenv.py b/setuptools/tests/test_virtualenv.py
index b009fbd6..6549a6c0 100644
--- a/setuptools/tests/test_virtualenv.py
+++ b/setuptools/tests/test_virtualenv.py
@@ -13,6 +13,17 @@ from .test_easy_install import make_nspkg_sdist
@pytest.fixture(autouse=True)
+def disable_requires_python(monkeypatch):
+ """
+ Disable Requires-Python on Python 2.7
+ """
+ if sys.version_info > (3,):
+ return
+
+ monkeypatch.setenv('PIP_IGNORE_REQUIRES_PYTHON', 'true')
+
+
+@pytest.fixture(autouse=True)
def pytest_virtualenv_works(virtualenv):
"""
pytest_virtualenv may not work. if it doesn't, skip these
diff --git a/tools/tox_pip.py b/tools/tox_pip.py
index 1b7eeda5..6f457bb2 100644
--- a/tools/tox_pip.py
+++ b/tools/tox_pip.py
@@ -38,18 +38,43 @@ def is_install_self(args):
)
-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 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):
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:])
diff --git a/tox.ini b/tox.ini
index aeae13ce..a5ce930f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -18,7 +18,6 @@ install_command = {[helpers]pip} install {opts} {packages}
list_dependencies_command = {[helpers]pip} freeze --all
setenv =
COVERAGE_FILE={toxworkdir}/.coverage.{envname}
- py27: PIP_IGNORE_REQUIRES_PYTHON=true
# TODO: The passed environment variables came from copying other tox.ini files
# These should probably be individually annotated to explain what needs them.
passenv=APPDATA HOMEDRIVE HOMEPATH windir APPVEYOR APPVEYOR_* CI CODECOV_* TRAVIS TRAVIS_* NETWORK_REQUIRED