mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-31 19:26:52 +00:00
Merge branch 'config-remove-config-caching' into 'master'
config: Remove checks for configs being previously parsed See merge request pycqa/flake8!408
This commit is contained in:
commit
990adcd56e
2 changed files with 13 additions and 54 deletions
|
|
@ -4,7 +4,7 @@ import configparser
|
|||
import logging
|
||||
import os.path
|
||||
import sys
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from flake8 import utils
|
||||
|
||||
|
|
@ -61,14 +61,6 @@ class ConfigFileFinder(object):
|
|||
|
||||
self.local_directory = os.path.abspath(os.curdir)
|
||||
|
||||
# caches to avoid double-reading config files
|
||||
self._local_configs = None
|
||||
self._local_found_files = [] # type: List[str]
|
||||
self._user_config = None
|
||||
# fmt: off
|
||||
self._cli_configs = {} # type: Dict[str, configparser.RawConfigParser]
|
||||
# fmt: on
|
||||
|
||||
@staticmethod
|
||||
def _read_config(*files):
|
||||
# type: (*str) -> Tuple[configparser.RawConfigParser, List[str]]
|
||||
|
|
@ -95,12 +87,10 @@ class ConfigFileFinder(object):
|
|||
def cli_config(self, files):
|
||||
# type: (str) -> configparser.RawConfigParser
|
||||
"""Read and parse the config file specified on the command-line."""
|
||||
if files not in self._cli_configs:
|
||||
config, found_files = self._read_config(files)
|
||||
if found_files:
|
||||
LOG.debug("Found cli configuration files: %s", found_files)
|
||||
self._cli_configs[files] = config
|
||||
return self._cli_configs[files]
|
||||
config, found_files = self._read_config(files)
|
||||
if found_files:
|
||||
LOG.debug("Found cli configuration files: %s", found_files)
|
||||
return config
|
||||
|
||||
def generate_possible_local_files(self):
|
||||
"""Find and generate all local config files."""
|
||||
|
|
@ -140,15 +130,10 @@ class ConfigFileFinder(object):
|
|||
|
||||
Return (config, found_config_files) tuple.
|
||||
"""
|
||||
if self._local_configs is None:
|
||||
config, found_files = self._read_config(
|
||||
*self.local_config_files()
|
||||
)
|
||||
if found_files:
|
||||
LOG.debug("Found local configuration files: %s", found_files)
|
||||
self._local_configs = config
|
||||
self._local_found_files = found_files
|
||||
return (self._local_configs, self._local_found_files)
|
||||
config, found_files = self._read_config(*self.local_config_files())
|
||||
if found_files:
|
||||
LOG.debug("Found local configuration files: %s", found_files)
|
||||
return (config, found_files)
|
||||
|
||||
def local_configs(self):
|
||||
"""Parse all local config files into one config object."""
|
||||
|
|
@ -162,12 +147,10 @@ class ConfigFileFinder(object):
|
|||
|
||||
def user_config(self):
|
||||
"""Parse the user config file into a config object."""
|
||||
if self._user_config is None:
|
||||
config, found_files = self._read_config(self.user_config_file())
|
||||
if found_files:
|
||||
LOG.debug("Found user configuration files: %s", found_files)
|
||||
self._user_config = config
|
||||
return self._user_config
|
||||
config, found_files = self._read_config(self.user_config_file())
|
||||
if found_files:
|
||||
LOG.debug("Found user configuration files: %s", found_files)
|
||||
return config
|
||||
|
||||
|
||||
class MergedConfigParser(object):
|
||||
|
|
|
|||
|
|
@ -34,18 +34,6 @@ def test_cli_config():
|
|||
assert parsed_config.has_section('flake8')
|
||||
|
||||
|
||||
def test_cli_config_double_read():
|
||||
"""Second request for CLI config is cached."""
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
parsed_config = finder.cli_config(CLI_SPECIFIED_FILEPATH)
|
||||
boom = Exception("second request for CLI config not cached")
|
||||
with mock.patch.object(finder, '_read_config', side_effect=boom):
|
||||
parsed_config_2 = finder.cli_config(CLI_SPECIFIED_FILEPATH)
|
||||
|
||||
assert parsed_config is parsed_config_2
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cwd,expected', [
|
||||
# Root directory of project
|
||||
(os.path.abspath('.'),
|
||||
|
|
@ -96,18 +84,6 @@ def test_local_configs():
|
|||
assert isinstance(finder.local_configs(), configparser.RawConfigParser)
|
||||
|
||||
|
||||
def test_local_configs_double_read():
|
||||
"""Second request for local configs is cached."""
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
first_read = finder.local_configs()
|
||||
boom = Exception("second request for local configs not cached")
|
||||
with mock.patch.object(finder, '_read_config', side_effect=boom):
|
||||
second_read = finder.local_configs()
|
||||
|
||||
assert first_read is second_read
|
||||
|
||||
|
||||
@pytest.mark.parametrize('files', [
|
||||
[BROKEN_CONFIG_PATH],
|
||||
[CLI_SPECIFIED_FILEPATH, BROKEN_CONFIG_PATH],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue