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.
This commit is contained in:
Eric N. Vander Weele 2019-10-01 08:48:18 +02:00
parent 32ebb4fa55
commit 95a88e3fcd
3 changed files with 15 additions and 8 deletions

View file

@ -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

View file

@ -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()

View file

@ -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()