mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 06:44:18 +00:00
Merge branch 'app-remove-make-config-finder' into 'master'
application: Inline creation of config.ConfigFileFinder See merge request pycqa/flake8!393
This commit is contained in:
commit
dbb6d7a109
4 changed files with 13 additions and 28 deletions
|
|
@ -10,6 +10,7 @@ import os.path
|
||||||
import flake8
|
import flake8
|
||||||
from flake8.formatting import base as formatter
|
from flake8.formatting import base as formatter
|
||||||
from flake8.main import application as app
|
from flake8.main import application as app
|
||||||
|
from flake8.options import config
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -30,9 +31,10 @@ def get_style_guide(**kwargs):
|
||||||
application = app.Application()
|
application = app.Application()
|
||||||
prelim_opts, remaining_args = application.parse_preliminary_options([])
|
prelim_opts, remaining_args = application.parse_preliminary_options([])
|
||||||
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
||||||
config_finder = application.make_config_finder(
|
config_finder = config.ConfigFileFinder(
|
||||||
application.program, prelim_opts.append_config
|
application.program, prelim_opts.append_config
|
||||||
)
|
)
|
||||||
|
|
||||||
application.find_plugins(
|
application.find_plugins(
|
||||||
config_finder, prelim_opts.config, prelim_opts.isolated
|
config_finder, prelim_opts.config, prelim_opts.isolated
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -131,23 +131,6 @@ class Application(object):
|
||||||
(self.result_count > 0) or self.catastrophic_failure
|
(self.result_count > 0) or self.catastrophic_failure
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def make_config_finder(program_name, extra_config_files):
|
|
||||||
# type: (str, List[str]) -> config.ConfigFileFinder
|
|
||||||
"""Make our ConfigFileFinder based on preliminary options.
|
|
||||||
|
|
||||||
:param str program_name:
|
|
||||||
Name of the current program (e.g., flake8).
|
|
||||||
:param list extra_config_files:
|
|
||||||
List of additional configuration files to be parsed for
|
|
||||||
configuration.
|
|
||||||
:returns:
|
|
||||||
The configuration file finder
|
|
||||||
:rtype:
|
|
||||||
config.ConfigFileFinder
|
|
||||||
"""
|
|
||||||
return config.ConfigFileFinder(program_name, extra_config_files)
|
|
||||||
|
|
||||||
def find_plugins(self, config_finder, config_file, ignore_config_files):
|
def find_plugins(self, config_finder, config_file, ignore_config_files):
|
||||||
# type: (config.ConfigFileFinder, Optional[str], bool) -> None
|
# type: (config.ConfigFileFinder, Optional[str], bool) -> None
|
||||||
"""Find and load the plugins for this application.
|
"""Find and load the plugins for this application.
|
||||||
|
|
@ -335,7 +318,7 @@ class Application(object):
|
||||||
# our legacy API calls to these same methods.
|
# our legacy API calls to these same methods.
|
||||||
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 = self.make_config_finder(
|
config_finder = config.ConfigFileFinder(
|
||||||
self.program, prelim_opts.append_config
|
self.program, prelim_opts.append_config
|
||||||
)
|
)
|
||||||
self.find_plugins(
|
self.find_plugins(
|
||||||
|
|
|
||||||
|
|
@ -346,9 +346,8 @@ class FileProcessor(object):
|
||||||
:rtype:
|
:rtype:
|
||||||
bool
|
bool
|
||||||
"""
|
"""
|
||||||
if (
|
if not self.options.disable_noqa and any(
|
||||||
not self.options.disable_noqa
|
defaults.NOQA_FILE.match(line) for line in self.lines
|
||||||
and any(defaults.NOQA_FILE.match(line) for line in self.lines)
|
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
elif any(defaults.NOQA_FILE.search(line) for line in self.lines):
|
elif any(defaults.NOQA_FILE.search(line) for line in self.lines):
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,16 @@ def test_get_style_guide():
|
||||||
mockedapp = mock.Mock()
|
mockedapp = mock.Mock()
|
||||||
mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
|
mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
|
||||||
mockedapp.program = 'flake8'
|
mockedapp.program = 'flake8'
|
||||||
config_finder = ConfigFileFinder(mockedapp.program, [])
|
with mock.patch('flake8.api.legacy.config.ConfigFileFinder') as mock_config_finder: # noqa: E501
|
||||||
mockedapp.make_config_finder.return_value = config_finder
|
config_finder = ConfigFileFinder(mockedapp.program, [])
|
||||||
with mock.patch('flake8.main.application.Application') as application:
|
mock_config_finder.return_value = config_finder
|
||||||
application.return_value = mockedapp
|
|
||||||
style_guide = api.get_style_guide()
|
with mock.patch('flake8.main.application.Application') as application:
|
||||||
|
application.return_value = mockedapp
|
||||||
|
style_guide = api.get_style_guide()
|
||||||
|
|
||||||
application.assert_called_once_with()
|
application.assert_called_once_with()
|
||||||
mockedapp.parse_preliminary_options.assert_called_once_with([])
|
mockedapp.parse_preliminary_options.assert_called_once_with([])
|
||||||
mockedapp.make_config_finder.assert_called_once_with(mockedapp.program, [])
|
|
||||||
mockedapp.find_plugins.assert_called_once_with(config_finder, None, False)
|
mockedapp.find_plugins.assert_called_once_with(config_finder, None, False)
|
||||||
mockedapp.register_plugin_options.assert_called_once_with()
|
mockedapp.register_plugin_options.assert_called_once_with()
|
||||||
mockedapp.parse_configuration_and_cli.assert_called_once_with(
|
mockedapp.parse_configuration_and_cli.assert_called_once_with(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue