summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-01-16 07:03:37 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2016-01-16 07:03:37 -0600
commit45d470927c85a680fcc4a4f902fe7da7f6e7606d (patch)
tree19e5b755c709bb01ac9c4581f4ac07ed9629fa48
parent6ef9089eb7aa0b7b3f302e38d0e2819571da118a (diff)
downloadflake8-45d470927c85a680fcc4a4f902fe7da7f6e7606d.tar.gz
Load plugins of each type idempotently
* Do not pass too many arguments to provide_options or register_options * Sub-class PluginTypeManager for both Listeners and Formatters
-rw-r--r--flake8/plugins/manager.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/flake8/plugins/manager.py b/flake8/plugins/manager.py
index 6e71f7e..81abdc4 100644
--- a/flake8/plugins/manager.py
+++ b/flake8/plugins/manager.py
@@ -164,6 +164,7 @@ class PluginTypeManager(object):
def __init__(self):
"""Initialize the plugin type's manager."""
self.manager = PluginManager(self.namespace)
+ self.plugins_loaded = False
@property
def names(self):
@@ -182,20 +183,29 @@ class PluginTypeManager(object):
if (method is not None and
isinstance(method, collections.Callable)):
return method(optmanager, *args, **kwargs)
+ return generated_function
def load_plugins(self):
+ """Load all plugins of this type that are managed by this manager."""
+ if self.plugins_loaded:
+ return
+
def load_plugin(plugin):
- return plugin.load()
+ return plugin.load_plugin()
- return list(self.manager.map(load_plugin))
+ plugins = list(self.manager.map(load_plugin))
+ # Do not set plugins_loaded if we run into an exception
+ self.plugins_loaded = True
+ return plugins
def register_options(self, optmanager):
"""Register all of the checkers' options to the OptionManager."""
+ self.load_plugins()
call_register_options = self._generate_call_function(
'register_options', optmanager,
)
- list(self.manager.map(call_register_options, optmanager))
+ list(self.manager.map(call_register_options))
def provide_options(self, optmanager, options, extra_args):
"""Provide parsed options and extra arguments to the plugins."""
@@ -203,8 +213,7 @@ class PluginTypeManager(object):
'provide_options', optmanager, options, extra_args,
)
- list(self.manager.map(call_provide_options, optmanager, options,
- extra_args))
+ list(self.manager.map(call_provide_options))
class Checkers(PluginTypeManager):
@@ -213,13 +222,13 @@ class Checkers(PluginTypeManager):
namespace = 'flake8.extension'
-class Listeners(object):
+class Listeners(PluginTypeManager):
"""All of the listeners registered through entry-points."""
namespace = 'flake8.listen'
-class ReportFormatters(object):
+class ReportFormatters(PluginTypeManager):
"""All of the report formatters registered through entry-points."""
namespace = 'flake8.report'