Skip to content

Commit

Permalink
Merge pull request #1981 from pypa/feature/deps-in-metadata
Browse files Browse the repository at this point in the history
Move test dependencies to package metadata.
  • Loading branch information
jaraco committed Feb 4, 2020
2 parents 7337658 + 91ede46 commit 54b76e6
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}-${{ hashFiles('tests/requirements.txt') }}-${{ hashFiles('tox.ini') }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
Expand Down
5 changes: 3 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
python:
version: 3
requirements_file: docs/requirements.txt
pip_install: false
extra_requirements:
- docs
pip_install: true
1 change: 1 addition & 0 deletions changelog.d/1981.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Setuptools now declares its ``tests`` and ``docs`` dependencies in metadata (extras).
5 changes: 0 additions & 5 deletions docs/requirements.txt

This file was deleted.

20 changes: 20 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,25 @@ exclude = *.tests
[options.extras_require]
ssl =
wincertstore==0.2; sys_platform=='win32'

certs =
certifi==2016.9.26

tests =
mock
pytest-flake8
flake8-2020; python_version>="3.6"
virtualenv>=13.0.0
pytest-virtualenv>=1.2.7
pytest>=3.7
wheel
coverage>=4.5.1
pytest-cov>=2.5.1
paver; python_version>="3.6"
futures; python_version=="2.7"
pip>=19.1 # For proper file:// URLs support.

docs =
sphinx
jaraco.packaging>=6.1
rst.linker>=1.9
11 changes: 11 additions & 0 deletions setuptools/tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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):
"""
Expand Down
61 changes: 53 additions & 8 deletions tools/tox_pip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import re


def remove_setuptools():
Expand All @@ -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:])
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ requires =
pip = python {toxinidir}/tools/tox_pip.py

[testenv]
deps=-r{toxinidir}/setuptools/tests/requirements.txt
pip_version = pip
install_command = {[helpers]pip} install {opts} {packages}
list_dependencies_command = {[helpers]pip} freeze --all
setenv =
COVERAGE_FILE={toxworkdir}/.coverage.{envname}
py{27,py2}: 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
commands=pytest --cov-config={toxinidir}/tox.ini --cov-report= {posargs}
usedevelop=True
extras =
tests


[testenv:coverage]
Expand All @@ -44,12 +44,12 @@ skip_install=True
commands=codecov -X gcov --file {toxworkdir}/coverage.xml

[testenv:docs]
deps = -r{toxinidir}/docs/requirements.txt
skip_install=True
extras =
docs
testing
changedir = docs
commands =
python -m bootstrap
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/build/html
sphinx-build -W -b man -d {envtmpdir}/doctrees docs docs/build/man
python -m sphinx . {toxinidir}/build/html

[coverage:run]
source=
Expand Down

0 comments on commit 54b76e6

Please sign in to comment.