Skip to content

Commit

Permalink
Merge pull request #1847 from pypa/bugfix/1787-python-requires-invalid
Browse files Browse the repository at this point in the history
Crash when invalid python_requires indicated in setup.cfg
  • Loading branch information
jaraco authored Oct 7, 2019
2 parents da3ccf5 + 2e3c34f commit 01bf4fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/1847.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In declarative config, now traps errors when invalid ``python_requires`` values are supplied.
2 changes: 2 additions & 0 deletions setuptools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.extern.packaging.version import LegacyVersion, parse
from setuptools.extern.packaging.specifiers import SpecifierSet
from setuptools.extern.six import string_types, PY3


Expand Down Expand Up @@ -554,6 +555,7 @@ def parsers(self):
'packages': self._parse_packages,
'entry_points': self._parse_file,
'py_modules': parse_list,
'python_requires': SpecifierSet,
}

def _parse_packages(self, value):
Expand Down
34 changes: 34 additions & 0 deletions setuptools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,40 @@ def test_data_files(self, tmpdir):
]
assert sorted(dist.data_files) == sorted(expected)

def test_python_requires_simple(self, tmpdir):
fake_env(
tmpdir,
DALS("""
[options]
python_requires=>=2.7
"""),
)
with get_dist(tmpdir) as dist:
dist.parse_config_files()

def test_python_requires_compound(self, tmpdir):
fake_env(
tmpdir,
DALS("""
[options]
python_requires=>=2.7,!=3.0.*
"""),
)
with get_dist(tmpdir) as dist:
dist.parse_config_files()

def test_python_requires_invalid(self, tmpdir):
fake_env(
tmpdir,
DALS("""
[options]
python_requires=invalid
"""),
)
with pytest.raises(Exception):
with get_dist(tmpdir) as dist:
dist.parse_config_files()


saved_dist_init = _Distribution.__init__

Expand Down

0 comments on commit 01bf4fb

Please sign in to comment.