diff options
| -rw-r--r-- | src/flake8/main/application.py | 1 | ||||
| -rw-r--r-- | src/flake8/options/config.py | 15 | ||||
| -rw-r--r-- | tests/unit/test_config_file_finder.py | 17 |
3 files changed, 30 insertions, 3 deletions
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 6a59e1a..b96a605 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -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) diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py index dab16c4..76a81cf 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 diff --git a/tests/unit/test_config_file_finder.py b/tests/unit/test_config_file_finder.py index d03118a..93d515a 100644 --- a/tests/unit/test_config_file_finder.py +++ b/tests/unit/test_config_file_finder.py @@ -127,6 +127,23 @@ def test_read_config_catches_decoding_errors(tmpdir): assert parsed == [] +def test_config_file_default_value(): + """Verify the default 'config_file' attribute value.""" + finder = config.ConfigFileFinder('flake8', []) + assert finder.config_file is None + + +def test_setting_config_file_value(): + """Verify the 'config_file' attribute matches constructed value.""" + config_file_value = 'flake8.ini' + finder = config.ConfigFileFinder( + 'flake8', + [], + config_file=config_file_value, + ) + assert finder.config_file == config_file_value + + def test_ignore_config_files_default_value(): """Verify the default 'ignore_config_files' attribute value.""" finder = config.ConfigFileFinder('flake8', []) |
