Commit b1615d12 authored by Jason R. Coombs's avatar Jason R. Coombs

Adopt distutils.dist.Distribution._set_command_options to support better string detection.

parent 80082fac
...@@ -14,6 +14,7 @@ import distutils.dist ...@@ -14,6 +14,7 @@ import distutils.dist
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
from distutils.util import strtobool from distutils.util import strtobool
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.fancy_getopt import translate_longopt
import itertools import itertools
from collections import defaultdict from collections import defaultdict
...@@ -626,6 +627,53 @@ class Distribution(_Distribution): ...@@ -626,6 +627,53 @@ class Distribution(_Distribution):
except ValueError as msg: except ValueError as msg:
raise DistutilsOptionError(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): def parse_config_files(self, filenames=None, ignore_option_errors=False):
"""Parses configuration files from various levels """Parses configuration files from various levels
and loads configuration. and loads configuration.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment