Skip to content

Commit 01bf4fb

Browse files
authored
Merge pull request #1847 from pypa/bugfix/1787-python-requires-invalid
Crash when invalid python_requires indicated in setup.cfg
2 parents da3ccf5 + 2e3c34f commit 01bf4fb

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

changelog.d/1847.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In declarative config, now traps errors when invalid ``python_requires`` values are supplied.

setuptools/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from distutils.errors import DistutilsOptionError, DistutilsFileError
1414
from setuptools.extern.packaging.version import LegacyVersion, parse
15+
from setuptools.extern.packaging.specifiers import SpecifierSet
1516
from setuptools.extern.six import string_types, PY3
1617

1718

@@ -554,6 +555,7 @@ def parsers(self):
554555
'packages': self._parse_packages,
555556
'entry_points': self._parse_file,
556557
'py_modules': parse_list,
558+
'python_requires': SpecifierSet,
557559
}
558560

559561
def _parse_packages(self, value):

setuptools/tests/test_config.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,40 @@ def test_data_files(self, tmpdir):
819819
]
820820
assert sorted(dist.data_files) == sorted(expected)
821821

822+
def test_python_requires_simple(self, tmpdir):
823+
fake_env(
824+
tmpdir,
825+
DALS("""
826+
[options]
827+
python_requires=>=2.7
828+
"""),
829+
)
830+
with get_dist(tmpdir) as dist:
831+
dist.parse_config_files()
832+
833+
def test_python_requires_compound(self, tmpdir):
834+
fake_env(
835+
tmpdir,
836+
DALS("""
837+
[options]
838+
python_requires=>=2.7,!=3.0.*
839+
"""),
840+
)
841+
with get_dist(tmpdir) as dist:
842+
dist.parse_config_files()
843+
844+
def test_python_requires_invalid(self, tmpdir):
845+
fake_env(
846+
tmpdir,
847+
DALS("""
848+
[options]
849+
python_requires=invalid
850+
"""),
851+
)
852+
with pytest.raises(Exception):
853+
with get_dist(tmpdir) as dist:
854+
dist.parse_config_files()
855+
822856

823857
saved_dist_init = _Distribution.__init__
824858

0 commit comments

Comments
 (0)