diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-01-26 21:45:33 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2019-01-26 21:45:33 -0500 |
commit | b1615d12435289c21853be2f4f40e523317998da (patch) | |
tree | 5d778a11909205757680ad5dd574f5971ebb0329 | |
parent | 80082faca2c530263e488e88f3d035de6f938007 (diff) | |
download | python-setuptools-git-b1615d12435289c21853be2f4f40e523317998da.tar.gz |
Adopt distutils.dist.Distribution._set_command_options to support better string detection.
-rw-r--r-- | setuptools/dist.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 4cc3bdfe..a7ebe73b 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -14,6 +14,7 @@ import distutils.dist from distutils.errors import DistutilsOptionError from distutils.util import strtobool from distutils.debug import DEBUG +from distutils.fancy_getopt import translate_longopt import itertools from collections import defaultdict @@ -626,6 +627,53 @@ class Distribution(_Distribution): except ValueError as msg: raise DistutilsOptionError(msg) + def _set_command_options(self, command_obj, option_dict=None): + """ + Set the options for 'command_obj' from 'option_dict'. Basically + this means copying elements of a dictionary ('option_dict') to + attributes of an instance ('command'). + + 'command_obj' must be a Command instance. If 'option_dict' is not + supplied, uses the standard option dictionary for this command + (from 'self.command_options'). + + (Adopted from distutils.dist.Distribution._set_command_options) + """ + command_name = command_obj.get_command_name() + if option_dict is None: + option_dict = self.get_option_dict(command_name) + + if DEBUG: + self.announce(" setting options for '%s' command:" % command_name) + for (option, (source, value)) in option_dict.items(): + if DEBUG: + self.announce(" %s = %s (from %s)" % (option, value, + source)) + try: + bool_opts = [translate_longopt(o) + for o in command_obj.boolean_options] + except AttributeError: + bool_opts = [] + try: + neg_opt = command_obj.negative_opt + except AttributeError: + neg_opt = {} + + try: + is_string = isinstance(value, str) + if option in neg_opt and is_string: + setattr(command_obj, neg_opt[option], not strtobool(value)) + elif option in bool_opts and is_string: + setattr(command_obj, option, strtobool(value)) + elif hasattr(command_obj, option): + setattr(command_obj, option, value) + else: + raise DistutilsOptionError( + "error in %s: command '%s' has no such option '%s'" + % (source, command_name, option)) + except ValueError as msg: + raise DistutilsOptionError(msg) + def parse_config_files(self, filenames=None, ignore_option_errors=False): """Parses configuration files from various levels and loads configuration. |