diff options
author | Sreejith Menon <sreejith_1729@yahoo.co.in> | 2018-10-28 19:52:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-28 19:52:20 -0400 |
commit | 1c226bdeb61dbd82419508dcc65b9969d0f42e16 (patch) | |
tree | 8182c4a80faed306e519b3566aa0251117f7ff23 /setuptools/config.py | |
parent | 717de8391f5ddfc507fcf2d36a49274f37ef5a16 (diff) | |
parent | 29f9cb087fd107f412e2a2f0df877e3b14a75be9 (diff) | |
download | external_python_setuptools-1c226bdeb61dbd82419508dcc65b9969d0f42e16.tar.gz external_python_setuptools-1c226bdeb61dbd82419508dcc65b9969d0f42e16.tar.bz2 external_python_setuptools-1c226bdeb61dbd82419508dcc65b9969d0f42e16.zip |
Merge branch 'master' into deprecate-requires
Diffstat (limited to 'setuptools/config.py')
-rw-r--r-- | setuptools/config.py | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/setuptools/config.py b/setuptools/config.py index 1f9c50f9..d1ac6734 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -2,7 +2,9 @@ from __future__ import absolute_import, unicode_literals import io import os import sys + import warnings +import functools from collections import defaultdict from functools import partial from functools import wraps @@ -63,6 +65,18 @@ def read_configuration( return configuration_to_dict(handlers) +def _get_option(target_obj, key): + """ + Given a target object and option key, get that option from + the target object, either through a get_{key} method or + from an attribute directly. + """ + getter_name = 'get_{key}'.format(**locals()) + by_attribute = functools.partial(getattr, target_obj, key) + getter = getattr(target_obj, getter_name, by_attribute) + return getter() + + def configuration_to_dict(handlers): """Returns configuration data gathered by given handlers as a dict. @@ -74,20 +88,9 @@ def configuration_to_dict(handlers): config_dict = defaultdict(dict) for handler in handlers: - - obj_alias = handler.section_prefix - target_obj = handler.target_obj - for option in handler.set_options: - getter = getattr(target_obj, 'get_%s' % option, None) - - if getter is None: - value = getattr(target_obj, option) - - else: - value = getter() - - config_dict[obj_alias][option] = value + value = _get_option(handler.target_obj, option) + config_dict[handler.section_prefix][option] = value return config_dict @@ -112,7 +115,8 @@ def parse_configuration( options.parse() meta = ConfigMetadataHandler( - distribution.metadata, command_options, ignore_option_errors, distribution.package_dir) + distribution.metadata, command_options, ignore_option_errors, + distribution.package_dir) meta.parse() return meta, options @@ -477,9 +481,12 @@ class ConfigMetadataHandler(ConfigHandler): # Be strict about versions loaded from file because it's easy to # accidentally include newlines and other unintended content if isinstance(parse(version), LegacyVersion): - raise DistutilsOptionError('Version loaded from %s does not comply with PEP 440: %s' % ( - value, version - )) + tmpl = ( + 'Version loaded from {value} does not ' + 'comply with PEP 440: {version}' + ) + raise DistutilsOptionError(tmpl.format(**locals())) + return version version = self._parse_attr(value, self.package_dir) @@ -537,12 +544,13 @@ class ConfigOptionsHandler(ConfigHandler): find_directives = ['find:', 'find_namespace:'] trimmed_value = value.strip() - if not trimmed_value in find_directives: + if trimmed_value not in find_directives: return self._parse_list(value) findns = trimmed_value == find_directives[1] if findns and not PY3: - raise DistutilsOptionError('find_namespace: directive is unsupported on Python < 3.3') + raise DistutilsOptionError( + 'find_namespace: directive is unsupported on Python < 3.3') # Read function arguments from a dedicated section. find_kwargs = self.parse_section_packages__find( |