config: Add 'config_file' parameter to ConfigFileFinder

The `--config` flag is passed into `MergedConfigParser.parse()` and the
module-level function `config.get_local_plugins()`.  Since both of these
places utilize the `ConfigFileFinder` object and the configuration file
override pertains to how configuration behaves, this incremental change
directly associates the `ConfigFileFinder` and the configuration file
override.
This commit is contained in:
Eric N. Vander Weele 2020-01-12 14:41:20 -08:00
parent 24c2693979
commit 153032f778
3 changed files with 30 additions and 3 deletions

View file

@ -324,6 +324,7 @@ 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)

View file

@ -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