Commit 810eb439 authored by idle sign's avatar idle sign

Added ConfigHandler.strict_mode.

parent 06715b63
......@@ -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):
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment