mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 15:44:17 +00:00
config: Add 'ignore_config_files' parameter to ConfigFileFinder
The `--isolated` 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 isolation pertains to how the `ConfigFileFinder` should behave with respect to isolation, this incremental change more directly associates the `ConfigFileFinder` and configuration file isolate.
This commit is contained in:
parent
4395b05605
commit
a5c17c1a19
3 changed files with 32 additions and 3 deletions
|
|
@ -335,7 +335,9 @@ class Application(object):
|
||||||
prelim_opts, remaining_args = self.parse_preliminary_options(argv)
|
prelim_opts, remaining_args = self.parse_preliminary_options(argv)
|
||||||
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
||||||
config_finder = config.ConfigFileFinder(
|
config_finder = config.ConfigFileFinder(
|
||||||
self.program, prelim_opts.append_config
|
self.program,
|
||||||
|
prelim_opts.append_config,
|
||||||
|
ignore_config_files=prelim_opts.isolated,
|
||||||
)
|
)
|
||||||
self.find_plugins(
|
self.find_plugins(
|
||||||
config_finder, prelim_opts.config, prelim_opts.isolated
|
config_finder, prelim_opts.config, prelim_opts.isolated
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,26 @@ __all__ = ("ConfigFileFinder", "MergedConfigParser")
|
||||||
class ConfigFileFinder(object):
|
class ConfigFileFinder(object):
|
||||||
"""Encapsulate the logic for finding and reading config files."""
|
"""Encapsulate the logic for finding and reading config files."""
|
||||||
|
|
||||||
def __init__(self, program_name, extra_config_files):
|
def __init__(
|
||||||
# type: (str, List[str]) -> None
|
self, program_name, extra_config_files, ignore_config_files=False
|
||||||
|
):
|
||||||
|
# type: (str, List[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 bool ignore_config_files:
|
||||||
|
Determine whether to ignore configuration files or not.
|
||||||
"""
|
"""
|
||||||
# The values of --append-config from the CLI
|
# The values of --append-config from the CLI
|
||||||
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 --isolated from the CLI.
|
||||||
|
self.ignore_config_files = ignore_config_files
|
||||||
|
|
||||||
# Platform specific settings
|
# Platform specific settings
|
||||||
self.is_windows = sys.platform == "win32"
|
self.is_windows = sys.platform == "win32"
|
||||||
self.xdg_home = os.environ.get(
|
self.xdg_home = os.environ.get(
|
||||||
|
|
|
||||||
|
|
@ -124,3 +124,23 @@ def test_read_config_catches_decoding_errors(tmpdir):
|
||||||
setup_cfg.write_binary(b'[x]\ny = \x81\x8d\x90\x9d')
|
setup_cfg.write_binary(b'[x]\ny = \x81\x8d\x90\x9d')
|
||||||
_, parsed = config.ConfigFileFinder._read_config(setup_cfg.strpath)
|
_, parsed = config.ConfigFileFinder._read_config(setup_cfg.strpath)
|
||||||
assert parsed == []
|
assert parsed == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_ignore_config_files_default_value():
|
||||||
|
"""Verify the default 'ignore_config_files' attribute value."""
|
||||||
|
finder = config.ConfigFileFinder('flake8', [])
|
||||||
|
assert finder.ignore_config_files is False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('ignore_config_files_arg', [
|
||||||
|
False,
|
||||||
|
True,
|
||||||
|
])
|
||||||
|
def test_setting_ignore_config_files_value(ignore_config_files_arg):
|
||||||
|
"""Verify the 'ignore_config_files' attribute matches constructed value."""
|
||||||
|
finder = config.ConfigFileFinder(
|
||||||
|
'flake8',
|
||||||
|
[],
|
||||||
|
ignore_config_files=ignore_config_files_arg
|
||||||
|
)
|
||||||
|
assert finder.ignore_config_files is ignore_config_files_arg
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue