summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-01-13 04:27:45 +0000
committerAnthony Sottile <asottile@umich.edu>2020-01-13 04:27:45 +0000
commit44d67e46f5ebe6bc458fe7b18a7b8821e7b2391e (patch)
tree578cd3787ffc2495df5eb4c2e3d62b6c9bc72248 /src
parent24c2693979612f1178c444bc991beaed58933a20 (diff)
parent1e3bad20dd17981b66121d959b28faf6614edd7e (diff)
downloadflake8-44d67e46f5ebe6bc458fe7b18a7b8821e7b2391e.tar.gz
Merge branch 'config-finder-config-file' into 'master'
Determine config file override from the ConfigFileFinder object See merge request pycqa/flake8!401
Diffstat (limited to 'src')
-rw-r--r--src/flake8/api/legacy.py5
-rw-r--r--src/flake8/main/application.py20
-rw-r--r--src/flake8/options/aggregator.py8
-rw-r--r--src/flake8/options/config.py39
4 files changed, 33 insertions, 39 deletions
diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py
index 40da7db..68df9a2 100644
--- a/src/flake8/api/legacy.py
+++ b/src/flake8/api/legacy.py
@@ -34,13 +34,14 @@ def get_style_guide(**kwargs):
config_finder = config.ConfigFileFinder(
application.program,
prelim_opts.append_config,
+ config_file=prelim_opts.config,
ignore_config_files=prelim_opts.isolated,
)
- application.find_plugins(config_finder, prelim_opts.config)
+ application.find_plugins(config_finder)
application.register_plugin_options()
application.parse_configuration_and_cli(
- config_finder, prelim_opts.config, remaining_args,
+ config_finder, remaining_args,
)
# We basically want application.initialize to be called but with these
# options set instead before we make our formatter, notifier, internal
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index 6a59e1a..001ad6c 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -131,8 +131,8 @@ class Application(object):
(self.result_count > 0) or self.catastrophic_failure
)
- def find_plugins(self, config_finder, config_file):
- # type: (config.ConfigFileFinder, Optional[str]) -> None
+ def find_plugins(self, config_finder):
+ # type: (config.ConfigFileFinder) -> None
"""Find and load the plugins for this application.
Set the :attr:`check_plugins` and :attr:`formatting_plugins` attributes
@@ -140,11 +140,8 @@ class Application(object):
: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).
"""
- local_plugins = config.get_local_plugins(config_finder, config_file)
+ local_plugins = config.get_local_plugins(config_finder)
sys.path.extend(local_plugins.paths)
@@ -167,7 +164,6 @@ class Application(object):
def parse_configuration_and_cli(
self,
config_finder, # type: config.ConfigFileFinder
- config_file, # type: Optional[str]
argv, # type: List[str]
):
# type: (...) -> None
@@ -175,14 +171,11 @@ class Application(object):
: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 list argv:
Command-line arguments passed in directly.
"""
self.options, self.args = aggregator.aggregate_options(
- self.option_manager, config_finder, config_file, argv,
+ self.option_manager, config_finder, argv,
)
self.running_against_diff = self.options.diff
@@ -324,12 +317,13 @@ class Application(object):
config_finder = config.ConfigFileFinder(
self.program,
prelim_opts.append_config,
+ config_file=prelim_opts.config,
ignore_config_files=prelim_opts.isolated,
)
- self.find_plugins(config_finder, prelim_opts.config)
+ self.find_plugins(config_finder)
self.register_plugin_options()
self.parse_configuration_and_cli(
- config_finder, prelim_opts.config, remaining_args,
+ config_finder, remaining_args,
)
self.make_formatter()
self.make_guide()
diff --git a/src/flake8/options/aggregator.py b/src/flake8/options/aggregator.py
index 939dfb3..bdcd6a3 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, Optional, Tuple
+from typing import List, Tuple
from flake8.options import config
from flake8.options.manager import OptionManager
@@ -16,7 +16,6 @@ LOG = logging.getLogger(__name__)
def aggregate_options(
manager, # type: OptionManager
config_finder, # type: config.ConfigFileFinder
- cli_config, # type: Optional[str]
argv, # type: List[str]
): # type: (...) -> Tuple[argparse.Namespace, List[str]]
"""Aggregate and merge CLI and config file options.
@@ -25,9 +24,6 @@ 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 list argv:
The list of remaining command-line argumentsthat were unknown during
preliminary option parsing to pass to ``manager.parse_args``.
@@ -46,7 +42,7 @@ def aggregate_options(
)
# Get the parsed config
- parsed_config = config_parser.parse(cli_config)
+ parsed_config = config_parser.parse()
# Extend the default ignore value with the extended default ignore list,
# registered by plugins.
diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py
index dab16c4..af163ca 100644
--- a/src/flake8/options/config.py
+++ b/src/flake8/options/config.py
@@ -4,7 +4,7 @@ import configparser
import logging
import os.path
import sys
-from typing import Dict, List, Tuple
+from typing import Dict, List, Optional, Tuple
from flake8 import utils
@@ -17,15 +17,21 @@ class ConfigFileFinder(object):
"""Encapsulate the logic for finding and reading config files."""
def __init__(
- self, program_name, extra_config_files, ignore_config_files=False
+ self,
+ program_name,
+ extra_config_files,
+ config_file=None,
+ ignore_config_files=False,
):
- # type: (str, List[str], bool) -> None
+ # type: (str, List[str], Optional[str], bool) -> None
"""Initialize object to find config files.
:param str program_name:
Name of the current program (e.g., flake8).
:param list extra_config_files:
Extra configuration files specified by the user to read.
+ :param str config_file:
+ Configuration file override to only read configuraiton from.
:param bool ignore_config_files:
Determine whether to ignore configuration files or not.
"""
@@ -33,6 +39,9 @@ class ConfigFileFinder(object):
extra_config_files = extra_config_files or []
self.extra_config_files = utils.normalize_paths(extra_config_files)
+ # The value of --config from the CLI.
+ self.config_file = config_file
+
# The value of --isolated from the CLI.
self.ignore_config_files = ignore_config_files
@@ -286,16 +295,13 @@ class MergedConfigParser(object):
return config
- def parse(self, cli_config=None):
+ def parse(self):
"""Parse and return the local and user config files.
First this copies over the parsed local configuration and then
iterates over the options in the user configuration and sets them if
they were not set by the local configuration file.
- :param str cli_config:
- Value of --config when specified at the command-line. Overrides
- all other config files.
:returns:
Dictionary of parsed configuration options
:rtype:
@@ -308,26 +314,23 @@ class MergedConfigParser(object):
)
return {}
- if cli_config:
+ if self.config_finder.config_file:
LOG.debug(
"Ignoring user and locally found configuration files. "
'Reading only configuration from "%s" specified via '
"--config by the user",
- cli_config,
+ self.config_finder.config_file,
)
- return self.parse_cli_config(cli_config)
+ return self.parse_cli_config(self.config_finder.config_file)
return self.merge_user_and_local_config()
-def get_local_plugins(config_finder, cli_config=None):
+def get_local_plugins(config_finder):
"""Get local plugins lists from config files.
: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.
:returns:
LocalPlugins namedtuple containing two lists of plugin strings,
one for extension (checker) plugins and one for report plugins.
@@ -342,14 +345,14 @@ def get_local_plugins(config_finder, cli_config=None):
)
return local_plugins
- if cli_config:
+ if config_finder.config_file:
LOG.debug(
'Reading local plugins only from "%s" specified via '
"--config by the user",
- cli_config,
+ config_finder.config_file,
)
- config = config_finder.cli_config(cli_config)
- config_files = [cli_config]
+ config = config_finder.cli_config(config_finder.config_file)
+ config_files = [config_finder.config_file]
else:
config, config_files = config_finder.local_configs_with_files()