From 95a88e3fcd84f45eb6c0869cb095ea9089dfed44 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Tue, 1 Oct 2019 08:48:18 +0200 Subject: [PATCH] application: Pass prelim opts to `.find_plugins()` The configuration file and boolean to ignore configuration files can be threaded through now that `.parse_preliminary_options_and_args()` returns options and arguments. --- src/flake8/api/legacy.py | 2 +- src/flake8/main/application.py | 17 +++++++++++------ tests/unit/test_legacy_api.py | 4 +++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py index b680346..a620930 100644 --- a/src/flake8/api/legacy.py +++ b/src/flake8/api/legacy.py @@ -33,7 +33,7 @@ def get_style_guide(**kwargs): ) flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file) application.make_config_finder(prelim_opts.append_config, prelim_args) - application.find_plugins() + application.find_plugins(prelim_opts.config, prelim_opts.isolated) application.register_plugin_options() application.parse_configuration_and_cli([]) # We basically want application.initialize to be called but with these diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 0eb1abd..0580766 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -174,8 +174,8 @@ class Application(object): self.option_manager.program_name, args, append_config ) - def find_plugins(self): - # type: () -> None + def find_plugins(self, config_file, ignore_config_files): + # type: (Optional[str], bool) -> None """Find and load the plugins for this application. If :attr:`check_plugins`, or :attr:`formatting_plugins` are ``None`` @@ -183,12 +183,17 @@ class Application(object): instance. Given the expense of finding plugins (via :mod:`entrypoints`) we want this to be idempotent and so only update those attributes if they are ``None``. + + :param str config_file: + The optional configuraiton file to override all other configuration + files (i.e., the --config option). + :param bool ignore_config_files: + Determine whether to parse configuration files or not. (i.e., the + --isolated option). """ if self.local_plugins is None: self.local_plugins = config.get_local_plugins( - self.config_finder, - self.prelim_opts.config, - self.prelim_opts.isolated, + self.config_finder, config_file, ignore_config_files ) sys.path.extend(self.local_plugins.paths) @@ -367,7 +372,7 @@ class Application(object): ) flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file) self.make_config_finder(prelim_opts.append_config, prelim_args) - self.find_plugins() + self.find_plugins(prelim_opts.config, prelim_opts.isolated) self.register_plugin_options() self.parse_configuration_and_cli(argv) self.make_formatter() diff --git a/tests/unit/test_legacy_api.py b/tests/unit/test_legacy_api.py index 23c975e..f36246c 100644 --- a/tests/unit/test_legacy_api.py +++ b/tests/unit/test_legacy_api.py @@ -12,6 +12,8 @@ def test_get_style_guide(): """Verify the methods called on our internal Application.""" prelim_opts = argparse.Namespace( append_config=[], + config=None, + isolated=False, output_file=None, verbose=0, ) @@ -28,7 +30,7 @@ def test_get_style_guide(): application.assert_called_once_with() mockedapp.parse_preliminary_options_and_args.assert_called_once_with([]) mockedapp.make_config_finder.assert_called_once_with([], []) - mockedapp.find_plugins.assert_called_once_with() + mockedapp.find_plugins.assert_called_once_with(None, False) mockedapp.register_plugin_options.assert_called_once_with() mockedapp.parse_configuration_and_cli.assert_called_once_with([]) mockedapp.make_formatter.assert_called_once_with()