mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 07:44:16 +00:00
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:
parent
24c2693979
commit
153032f778
3 changed files with 30 additions and 3 deletions
|
|
@ -324,6 +324,7 @@ class Application(object):
|
||||||
config_finder = config.ConfigFileFinder(
|
config_finder = config.ConfigFileFinder(
|
||||||
self.program,
|
self.program,
|
||||||
prelim_opts.append_config,
|
prelim_opts.append_config,
|
||||||
|
config_file=prelim_opts.config,
|
||||||
ignore_config_files=prelim_opts.isolated,
|
ignore_config_files=prelim_opts.isolated,
|
||||||
)
|
)
|
||||||
self.find_plugins(config_finder, prelim_opts.config)
|
self.find_plugins(config_finder, prelim_opts.config)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import configparser
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
from typing import Dict, List, Tuple
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from flake8 import utils
|
from flake8 import utils
|
||||||
|
|
||||||
|
|
@ -17,15 +17,21 @@ class ConfigFileFinder(object):
|
||||||
"""Encapsulate the logic for finding and reading config files."""
|
"""Encapsulate the logic for finding and reading config files."""
|
||||||
|
|
||||||
def __init__(
|
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.
|
"""Initialize object to find config files.
|
||||||
|
|
||||||
:param str program_name:
|
:param str program_name:
|
||||||
Name of the current program (e.g., flake8).
|
Name of the current program (e.g., flake8).
|
||||||
:param list extra_config_files:
|
:param list extra_config_files:
|
||||||
Extra configuration files specified by the user to read.
|
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:
|
:param bool ignore_config_files:
|
||||||
Determine whether to ignore configuration files or not.
|
Determine whether to ignore configuration files or not.
|
||||||
"""
|
"""
|
||||||
|
|
@ -33,6 +39,9 @@ class ConfigFileFinder(object):
|
||||||
extra_config_files = extra_config_files or []
|
extra_config_files = extra_config_files or []
|
||||||
self.extra_config_files = utils.normalize_paths(extra_config_files)
|
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.
|
# The value of --isolated from the CLI.
|
||||||
self.ignore_config_files = ignore_config_files
|
self.ignore_config_files = ignore_config_files
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,23 @@ def test_read_config_catches_decoding_errors(tmpdir):
|
||||||
assert parsed == []
|
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():
|
def test_ignore_config_files_default_value():
|
||||||
"""Verify the default 'ignore_config_files' attribute value."""
|
"""Verify the default 'ignore_config_files' attribute value."""
|
||||||
finder = config.ConfigFileFinder('flake8', [])
|
finder = config.ConfigFileFinder('flake8', [])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue