diff options
| author | Anthony Sottile <asottile@umich.edu> | 2019-12-03 18:25:50 +0000 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2019-12-03 18:25:50 +0000 |
| commit | bb61b3df82a938f7cd1ca32daab4a31e4586b281 (patch) | |
| tree | f270359db263004ba481a5ca15bec89b0ec2a527 | |
| parent | 21d2adf21f86471d0bf56e6d444764aa3bb35884 (diff) | |
| parent | 9fa566398627ea5696cc9a526597c500e4278401 (diff) | |
| download | flake8-bb61b3df82a938f7cd1ca32daab4a31e4586b281.tar.gz | |
Merge branch 'app-remove-make-config-finder' into 'master'
application: Inline creation of config.ConfigFileFinder
See merge request pycqa/flake8!393
| -rw-r--r-- | src/flake8/api/legacy.py | 4 | ||||
| -rw-r--r-- | src/flake8/main/application.py | 19 | ||||
| -rw-r--r-- | src/flake8/processor.py | 5 | ||||
| -rw-r--r-- | tests/unit/test_legacy_api.py | 13 |
4 files changed, 13 insertions, 28 deletions
diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py index ac3fabb..2761163 100644 --- a/src/flake8/api/legacy.py +++ b/src/flake8/api/legacy.py @@ -10,6 +10,7 @@ import os.path import flake8 from flake8.formatting import base as formatter from flake8.main import application as app +from flake8.options import config LOG = logging.getLogger(__name__) @@ -30,9 +31,10 @@ def get_style_guide(**kwargs): application = app.Application() prelim_opts, remaining_args = application.parse_preliminary_options([]) 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.find_plugins( config_finder, prelim_opts.config, prelim_opts.isolated ) diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 19d7710..63db8e1 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -131,23 +131,6 @@ class Application(object): (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): # type: (config.ConfigFileFinder, Optional[str], bool) -> None """Find and load the plugins for this application. @@ -335,7 +318,7 @@ class Application(object): # our legacy API calls to these same methods. prelim_opts, remaining_args = self.parse_preliminary_options(argv) 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.find_plugins( diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 0fd650b..498b9c7 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -346,9 +346,8 @@ class FileProcessor(object): :rtype: bool """ - if ( - not self.options.disable_noqa - and any(defaults.NOQA_FILE.match(line) for line in self.lines) + if not self.options.disable_noqa and any( + defaults.NOQA_FILE.match(line) for line in self.lines ): return True elif any(defaults.NOQA_FILE.search(line) for line in self.lines): diff --git a/tests/unit/test_legacy_api.py b/tests/unit/test_legacy_api.py index 026fdc3..8f6045e 100644 --- a/tests/unit/test_legacy_api.py +++ b/tests/unit/test_legacy_api.py @@ -21,15 +21,16 @@ def test_get_style_guide(): mockedapp = mock.Mock() mockedapp.parse_preliminary_options.return_value = (prelim_opts, []) mockedapp.program = 'flake8' - config_finder = ConfigFileFinder(mockedapp.program, []) - mockedapp.make_config_finder.return_value = config_finder - with mock.patch('flake8.main.application.Application') as application: - application.return_value = mockedapp - style_guide = api.get_style_guide() + with mock.patch('flake8.api.legacy.config.ConfigFileFinder') as mock_config_finder: # noqa: E501 + config_finder = ConfigFileFinder(mockedapp.program, []) + mock_config_finder.return_value = config_finder + + with mock.patch('flake8.main.application.Application') as application: + application.return_value = mockedapp + style_guide = api.get_style_guide() application.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.register_plugin_options.assert_called_once_with() mockedapp.parse_configuration_and_cli.assert_called_once_with( |
