~anitanayak/charms/trusty/ibm-mq/ibm-mq-trusty

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/flake8/options/aggregator.py

  • Committer: Anita Nayak
  • Date: 2016-10-24 07:10:08 UTC
  • Revision ID: anitanayak@in.ibm.com-20161024071008-tqk3cefak6nc1c69
checking in after fixing lint errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Aggregation function for CLI specified options and config file options.
 
2
 
 
3
This holds the logic that uses the collected and merged config files and
 
4
applies the user-specified command-line configuration on top of it.
 
5
"""
 
6
import logging
 
7
 
 
8
from flake8 import utils
 
9
from flake8.options import config
 
10
 
 
11
LOG = logging.getLogger(__name__)
 
12
 
 
13
 
 
14
def aggregate_options(manager, arglist=None, values=None):
 
15
    """Aggregate and merge CLI and config file options.
 
16
 
 
17
    :param flake8.option.manager.OptionManager manager:
 
18
        The instance of the OptionManager that we're presently using.
 
19
    :param list arglist:
 
20
        The list of arguments to pass to ``manager.parse_args``. In most cases
 
21
        this will be None so ``parse_args`` uses ``sys.argv``. This is mostly
 
22
        available to make testing easier.
 
23
    :param optparse.Values values:
 
24
        Previously parsed set of parsed options.
 
25
    :returns:
 
26
        Tuple of the parsed options and extra arguments returned by
 
27
        ``manager.parse_args``.
 
28
    :rtype:
 
29
        tuple(optparse.Values, list)
 
30
    """
 
31
    # Get defaults from the option parser
 
32
    default_values, _ = manager.parse_args([], values=values)
 
33
    # Get original CLI values so we can find additional config file paths and
 
34
    # see if --config was specified.
 
35
    original_values, original_args = manager.parse_args(arglist)
 
36
    extra_config_files = utils.normalize_paths(original_values.append_config)
 
37
 
 
38
    # Make our new configuration file mergerator
 
39
    config_parser = config.MergedConfigParser(
 
40
        option_manager=manager,
 
41
        extra_config_files=extra_config_files,
 
42
        args=original_args,
 
43
    )
 
44
 
 
45
    # Get the parsed config
 
46
    parsed_config = config_parser.parse(original_values.config,
 
47
                                        original_values.isolated)
 
48
 
 
49
    # Extend the default ignore value with the extended default ignore list,
 
50
    # registered by plugins.
 
51
    extended_default_ignore = manager.extended_default_ignore.copy()
 
52
    LOG.debug('Extended default ignore list: %s',
 
53
              list(extended_default_ignore))
 
54
    extended_default_ignore.update(default_values.ignore)
 
55
    default_values.ignore = list(extended_default_ignore)
 
56
    LOG.debug('Merged default ignore list: %s', default_values.ignore)
 
57
 
 
58
    extended_default_select = manager.extended_default_select.copy()
 
59
    LOG.debug('Extended default select list: %s',
 
60
              list(extended_default_select))
 
61
    default_values.extended_default_select = extended_default_select
 
62
 
 
63
    # Merge values parsed from config onto the default values returned
 
64
    for config_name, value in parsed_config.items():
 
65
        dest_name = config_name
 
66
        # If the config name is somehow different from the destination name,
 
67
        # fetch the destination name from our Option
 
68
        if not hasattr(default_values, config_name):
 
69
            dest_name = config_parser.config_options[config_name].dest
 
70
 
 
71
        LOG.debug('Overriding default value of (%s) for "%s" with (%s)',
 
72
                  getattr(default_values, dest_name, None),
 
73
                  dest_name,
 
74
                  value)
 
75
        # Override the default values with the config values
 
76
        setattr(default_values, dest_name, value)
 
77
 
 
78
    # Finally parse the command-line options
 
79
    return manager.parse_args(arglist, default_values)