summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-12-30 00:20:42 +0000
committerAnthony Sottile <asottile@umich.edu>2019-12-30 00:20:42 +0000
commit20906d43046096c31dfcd9b8bc536dbd21f043ef (patch)
treebe8cf25e4c6514ed9c71427c44d34bef6d3f23f3 /src
parentbb61b3df82a938f7cd1ca32daab4a31e4586b281 (diff)
parent738c8490ec56fc364f4229df2c7c9adca8d1d4f2 (diff)
downloadflake8-20906d43046096c31dfcd9b8bc536dbd21f043ef.tar.gz
Merge branch 'aggregator-config-isolated-fix' into 'master'
aggregator: Forward --config and --isolated options during aggregation Closes #605 See merge request pycqa/flake8!395
Diffstat (limited to 'src')
-rw-r--r--src/flake8/api/legacy.py7
-rw-r--r--src/flake8/main/application.py29
-rw-r--r--src/flake8/options/aggregator.py17
3 files changed, 41 insertions, 12 deletions
diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py
index 2761163..fe3b405 100644
--- a/src/flake8/api/legacy.py
+++ b/src/flake8/api/legacy.py
@@ -39,7 +39,12 @@ def get_style_guide(**kwargs):
config_finder, prelim_opts.config, prelim_opts.isolated
)
application.register_plugin_options()
- application.parse_configuration_and_cli(config_finder, remaining_args)
+ application.parse_configuration_and_cli(
+ config_finder,
+ prelim_opts.config,
+ prelim_opts.isolated,
+ remaining_args,
+ )
# We basically want application.initialize to be called but with these
# options set instead before we make our formatter, notifier, internal
# style guide and file checker manager.
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index 63db8e1..791d5af 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -169,17 +169,33 @@ class Application(object):
self.check_plugins.register_plugin_versions(self.option_manager)
self.formatting_plugins.register_options(self.option_manager)
- def parse_configuration_and_cli(self, config_finder, argv):
- # type: (config.ConfigFileFinder, List[str]) -> None
+ def parse_configuration_and_cli(
+ self,
+ config_finder, # type: config.ConfigFileFinder
+ config_file, # type: Optional[str]
+ ignore_config_files, # type: bool
+ argv, # type: List[str]
+ ):
+ # type: (...) -> None
"""Parse configuration files and the CLI options.
:param config.ConfigFileFinder config_finder:
The finder for finding and reading configuration files.
+ :param str config_file:
+ The optional configuraiton file to override all other configuration
+ files (i.e., the --config option).
+ :param bool ignore_config_files:
+ Determine whether to parse configuration files or not. (i.e., the
+ --isolated option).
:param list argv:
Command-line arguments passed in directly.
"""
self.options, self.args = aggregator.aggregate_options(
- self.option_manager, config_finder, argv
+ self.option_manager,
+ config_finder,
+ config_file,
+ ignore_config_files,
+ argv,
)
self.running_against_diff = self.options.diff
@@ -325,7 +341,12 @@ class Application(object):
config_finder, prelim_opts.config, prelim_opts.isolated
)
self.register_plugin_options()
- self.parse_configuration_and_cli(config_finder, remaining_args)
+ self.parse_configuration_and_cli(
+ config_finder,
+ prelim_opts.config,
+ prelim_opts.isolated,
+ remaining_args,
+ )
self.make_formatter()
self.make_guide()
self.make_file_checker_manager()
diff --git a/src/flake8/options/aggregator.py b/src/flake8/options/aggregator.py
index 719160a..58d1022 100644
--- a/src/flake8/options/aggregator.py
+++ b/src/flake8/options/aggregator.py
@@ -5,7 +5,7 @@ applies the user-specified command-line configuration on top of it.
"""
import argparse
import logging
-from typing import List, Tuple
+from typing import List, Optional, Tuple
from flake8.options import config
from flake8.options.manager import OptionManager
@@ -16,6 +16,8 @@ LOG = logging.getLogger(__name__)
def aggregate_options(
manager, # type: OptionManager
config_finder, # type: config.ConfigFileFinder
+ cli_config, # type: Optional[str]
+ isolated, # type: bool
argv, # type: List[str]
): # type: (...) -> Tuple[argparse.Namespace, List[str]]
"""Aggregate and merge CLI and config file options.
@@ -24,6 +26,12 @@ def aggregate_options(
The instance of the OptionManager that we're presently using.
:param flake8.options.config.ConfigFileFinder config_finder:
The config file finder to use.
+ :param str cli_config:
+ Value of --config when specified at the command-line. Overrides
+ all other config files.
+ :param bool isolated:
+ Determines if we should parse configuration files at all or not.
+ If running in isolated mode, we ignore all configuration files
:param list argv:
The list of remaining command-line argumentsthat were unknown during
preliminary option parsing to pass to ``manager.parse_args``.
@@ -35,9 +43,6 @@ def aggregate_options(
"""
# Get defaults from the option parser
default_values, _ = manager.parse_args([])
- # Get original CLI values so we can find additional config file paths and
- # see if --config was specified.
- original_values, _ = manager.parse_args(argv)
# Make our new configuration file mergerator
config_parser = config.MergedConfigParser(
@@ -45,9 +50,7 @@ def aggregate_options(
)
# Get the parsed config
- parsed_config = config_parser.parse(
- original_values.config, original_values.isolated
- )
+ parsed_config = config_parser.parse(cli_config, isolated)
# Extend the default ignore value with the extended default ignore list,
# registered by plugins.