diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2018-10-28 14:16:19 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2018-10-28 14:16:31 -0400 |
commit | 42fe2eb166a3a1b2d31f0be93ad034ec48ea9b38 (patch) | |
tree | 1803ffa9b5e3ceda1689c482a2d5f8add8159296 /setuptools/config.py | |
parent | 9ad8e0dd09dc7f8c22f7cf51a5c83b7c788b50d7 (diff) | |
download | external_python_setuptools-42fe2eb166a3a1b2d31f0be93ad034ec48ea9b38.tar.gz external_python_setuptools-42fe2eb166a3a1b2d31f0be93ad034ec48ea9b38.tar.bz2 external_python_setuptools-42fe2eb166a3a1b2d31f0be93ad034ec48ea9b38.zip |
Extract _get_option function for getting an option from getter or attribute.
Diffstat (limited to 'setuptools/config.py')
-rw-r--r-- | setuptools/config.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/setuptools/config.py b/setuptools/config.py index 4cc1cb38..302d633f 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals import io import os import sys +import functools from collections import defaultdict from functools import partial from importlib import import_module @@ -61,6 +62,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,17 +87,9 @@ def configuration_to_dict(handlers): 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() - + value = _get_option(handler.target_obj, option) config_dict[obj_alias][option] = value return config_dict |