aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/config.py
diff options
context:
space:
mode:
authoridle sign <idlesign@yandex.ru>2016-12-10 12:06:26 +0700
committerJason R. Coombs <jaraco@jaraco.com>2016-12-10 11:23:00 -0500
commit56dea7f0334f60603d4ca6a884ca523fe3389ef3 (patch)
tree0bd0b074883e4d04d87a22fae43c70d9ded5cf8f /setuptools/config.py
parentac9997648d89131412eacbb198e2d3a7c97f69e4 (diff)
downloadexternal_python_setuptools-56dea7f0334f60603d4ca6a884ca523fe3389ef3.tar.gz
external_python_setuptools-56dea7f0334f60603d4ca6a884ca523fe3389ef3.tar.bz2
external_python_setuptools-56dea7f0334f60603d4ca6a884ca523fe3389ef3.zip
`read_configuration()` now accepts `ignore_option_errors`.
Diffstat (limited to 'setuptools/config.py')
-rw-r--r--setuptools/config.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/setuptools/config.py b/setuptools/config.py
index 889dc683..007d24e2 100644
--- a/setuptools/config.py
+++ b/setuptools/config.py
@@ -10,7 +10,8 @@ from setuptools.py26compat import import_module
from setuptools.extern.six import string_types
-def read_configuration(filepath, find_others=False):
+def read_configuration(
+ filepath, find_others=False, ignore_option_errors=False):
"""Read given configuration file and returns options from it as a dict.
:param str|unicode filepath: Path to configuration file
@@ -19,6 +20,11 @@ def read_configuration(filepath, find_others=False):
:param bool find_others: Whether to search for other configuration files
which could be on in various places.
+ :param bool ignore_option_errors: Whether to silently ignore
+ options, values of which could not be resolved (e.g. due to exceptions
+ in directives such as file:, attr:, etc.).
+ If False exceptions are propagated as expected.
+
:rtype: dict
"""
from setuptools.dist import Distribution, _Distribution
@@ -40,7 +46,9 @@ def read_configuration(filepath, find_others=False):
_Distribution.parse_config_files(dist, filenames=filenames)
- handlers = parse_configuration(dist, dist.command_options)
+ handlers = parse_configuration(
+ dist, dist.command_options,
+ ignore_option_errors=ignore_option_errors)
os.chdir(current_directory)
@@ -76,7 +84,8 @@ def configuration_to_dict(handlers):
return config_dict
-def parse_configuration(distribution, command_options):
+def parse_configuration(
+ distribution, command_options, ignore_option_errors=False):
"""Performs additional parsing of configuration options
for a distribution.
@@ -84,12 +93,18 @@ def parse_configuration(distribution, command_options):
:param Distribution distribution:
:param dict command_options:
+ :param bool ignore_option_errors: Whether to silently ignore
+ options, values of which could not be resolved (e.g. due to exceptions
+ in directives such as file:, attr:, etc.).
+ If False exceptions are propagated as expected.
:rtype: list
"""
- meta = ConfigMetadataHandler(distribution.metadata, command_options)
+ meta = ConfigMetadataHandler(
+ distribution.metadata, command_options, ignore_option_errors)
meta.parse()
- options = ConfigOptionsHandler(distribution, command_options)
+ options = ConfigOptionsHandler(
+ distribution, command_options, ignore_option_errors)
options.parse()
return [meta, options]
@@ -111,7 +126,7 @@ class ConfigHandler(object):
"""
- def __init__(self, target_obj, options):
+ def __init__(self, target_obj, options, ignore_option_errors=False):
sections = {}
section_prefix = self.section_prefix
@@ -122,6 +137,7 @@ class ConfigHandler(object):
section_name = section_name.replace(section_prefix, '').strip('.')
sections[section_name] = section_options
+ self.ignore_option_errors = ignore_option_errors
self.target_obj = target_obj
self.sections = sections
self.set_options = []
@@ -148,9 +164,19 @@ class ConfigHandler(object):
# Already inhabited. Skipping.
return
+ skip_option = False
parser = self.parsers.get(option_name)
if parser:
- value = parser(value)
+ try:
+ value = parser(value)
+
+ except Exception:
+ skip_option = True
+ if not self.ignore_option_errors:
+ raise
+
+ if skip_option:
+ return
setter = getattr(target_obj, 'set_%s' % option_name, None)
if setter is None: