From ad043d61d3bfff3ca69f477f44a718597a34e779 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 28 Oct 2018 14:05:57 -0400 Subject: Feed the hobgoblins (delint). --- setuptools/config.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'setuptools') diff --git a/setuptools/config.py b/setuptools/config.py index 73a3bf70..4cc1cb38 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -110,7 +110,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 @@ -458,9 +459,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) @@ -518,12 +522,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( -- cgit v1.2.3 From 42fe2eb166a3a1b2d31f0be93ad034ec48ea9b38 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 28 Oct 2018 14:16:19 -0400 Subject: Extract _get_option function for getting an option from getter or attribute. --- setuptools/config.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'setuptools') 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 -- cgit v1.2.3 From 9543875b93ab646e6c1f5ded7164d108de498852 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 28 Oct 2018 14:17:27 -0400 Subject: Inline variable --- setuptools/config.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'setuptools') diff --git a/setuptools/config.py b/setuptools/config.py index 302d633f..15d18672 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -85,12 +85,9 @@ def configuration_to_dict(handlers): config_dict = defaultdict(dict) for handler in handlers: - - obj_alias = handler.section_prefix - for option in handler.set_options: value = _get_option(handler.target_obj, option) - config_dict[obj_alias][option] = value + config_dict[handler.section_prefix][option] = value return config_dict -- cgit v1.2.3