From 810eb439a629e1b2bc2d078f138126356e95a9bc Mon Sep 17 00:00:00 2001 From: idle sign Date: Sun, 4 Dec 2016 10:41:54 +0700 Subject: Added ConfigHandler.strict_mode. --- setuptools/config.py | 21 +++++++++++++++++++-- setuptools/tests/test_config.py | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/setuptools/config.py b/setuptools/config.py index 94b2ab17..3546ace9 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -12,6 +12,16 @@ class ConfigHandler(object): """Handles metadata supplied in configuration files.""" section_prefix = None + """Prefix for config sections handled by this handler. + Must be provided by class heirs. + + """ + + strict_mode = True + """Flag. Whether unknown options in config should + raise DistutilsOptionError exception, or pass silently. + + """ def __init__(self, target_obj, options): sections = {} @@ -174,9 +184,11 @@ class ConfigHandler(object): for (name, (_, value)) in section_options.items(): try: self[name] = value + except KeyError: - raise DistutilsOptionError( - 'Unknown distribution option: %s' % name) + if self.strict_mode: + raise DistutilsOptionError( + 'Unknown distribution option: %s' % name) def parse(self): """Parses configuration file items from one @@ -203,6 +215,11 @@ class ConfigHandler(object): class ConfigMetadataHandler(ConfigHandler): section_prefix = 'metadata' + strict_mode = False + """We need to keep it loose, to be compatible with `pbr` package + which also uses `metadata` section. + + """ @property def parsers(self): diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index d044cbac..f1b1aa3f 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -130,8 +130,7 @@ class TestMetadata: 'unknown = some\n' ) with get_dist(tmpdir, parse=False) as dist: - with pytest.raises(DistutilsOptionError): - dist.parse_config_files() + dist.parse_config_files() # Skip unknown. def test_usupported_section(self, tmpdir): @@ -274,6 +273,18 @@ class TestOptions: with get_dist(tmpdir) as dist: assert dist.packages == ['fake_package'] + def test_unknown_options_item(self, tmpdir): + + fake_env( + tmpdir, + '[options]\n' + 'zip_safe = True\n' + 'usr_2to3 = 1\n' + ) + with get_dist(tmpdir, parse=False) as dist: + with pytest.raises(DistutilsOptionError): + dist.parse_config_files() + def test_extras_require(self, tmpdir): fake_env( tmpdir, -- cgit v1.2.3