mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
Merge branch 'aggregate_options-simplify-function-definition' into 'master'
aggregator: Simplify 'aggregate_options' function definition See merge request pycqa/flake8!376
This commit is contained in:
commit
3989b47a71
1 changed files with 14 additions and 10 deletions
|
|
@ -3,26 +3,30 @@
|
||||||
This holds the logic that uses the collected and merged config files and
|
This holds the logic that uses the collected and merged config files and
|
||||||
applies the user-specified command-line configuration on top of it.
|
applies the user-specified command-line configuration on top of it.
|
||||||
"""
|
"""
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
from flake8.options import config
|
from flake8.options import config
|
||||||
|
from flake8.options.manager import OptionManager
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def aggregate_options(manager, config_finder, arglist=None, values=None):
|
def aggregate_options(
|
||||||
|
manager, # type: OptionManager
|
||||||
|
config_finder, # type: config.ConfigFileFinder
|
||||||
|
argv, # type: List[str]
|
||||||
|
): # type: (...) -> Tuple[argparse.Namespace, List[str]]
|
||||||
"""Aggregate and merge CLI and config file options.
|
"""Aggregate and merge CLI and config file options.
|
||||||
|
|
||||||
:param flake8.options.manager.OptionManager manager:
|
:param flake8.options.manager.OptionManager manager:
|
||||||
The instance of the OptionManager that we're presently using.
|
The instance of the OptionManager that we're presently using.
|
||||||
:param flake8.options.config.ConfigFileFinder config_finder:
|
:param flake8.options.config.ConfigFileFinder config_finder:
|
||||||
The config file finder to use.
|
The config file finder to use.
|
||||||
:param list arglist:
|
:param list argv:
|
||||||
The list of arguments to pass to ``manager.parse_args``. In most cases
|
The list of remaining command-line argumentsthat were unknown during
|
||||||
this will be None so ``parse_args`` uses ``sys.argv``. This is mostly
|
preliminary option parsing to pass to ``manager.parse_args``.
|
||||||
available to make testing easier.
|
|
||||||
:param argparse.Namespace values:
|
|
||||||
Previously parsed set of parsed options.
|
|
||||||
:returns:
|
:returns:
|
||||||
Tuple of the parsed options and extra arguments returned by
|
Tuple of the parsed options and extra arguments returned by
|
||||||
``manager.parse_args``.
|
``manager.parse_args``.
|
||||||
|
|
@ -30,10 +34,10 @@ def aggregate_options(manager, config_finder, arglist=None, values=None):
|
||||||
tuple(argparse.Namespace, list)
|
tuple(argparse.Namespace, list)
|
||||||
"""
|
"""
|
||||||
# Get defaults from the option parser
|
# Get defaults from the option parser
|
||||||
default_values, _ = manager.parse_args([], values=values)
|
default_values, _ = manager.parse_args([])
|
||||||
# Get original CLI values so we can find additional config file paths and
|
# Get original CLI values so we can find additional config file paths and
|
||||||
# see if --config was specified.
|
# see if --config was specified.
|
||||||
original_values, _ = manager.parse_args(arglist)
|
original_values, _ = manager.parse_args(argv)
|
||||||
|
|
||||||
# Make our new configuration file mergerator
|
# Make our new configuration file mergerator
|
||||||
config_parser = config.MergedConfigParser(
|
config_parser = config.MergedConfigParser(
|
||||||
|
|
@ -79,4 +83,4 @@ def aggregate_options(manager, config_finder, arglist=None, values=None):
|
||||||
setattr(default_values, dest_name, value)
|
setattr(default_values, dest_name, value)
|
||||||
|
|
||||||
# Finally parse the command-line options
|
# Finally parse the command-line options
|
||||||
return manager.parse_args(arglist, default_values)
|
return manager.parse_args(argv, default_values)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue