summaryrefslogtreecommitdiff
path: root/flake8/plugins/manager.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-05-28 07:54:07 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-05-28 11:57:18 -0500
commit91e07ebcffc0d4ecc472bb0031113f6030f43a20 (patch)
tree02e64b6e6c643c4709f19bf77b4663fc23ea8cca /flake8/plugins/manager.py
parent50d74e3cce34e3047bcb24a2cf7cd85e5a7c1163 (diff)
downloadflake8-91e07ebcffc0d4ecc472bb0031113f6030f43a20.tar.gz
Refactor off-by-default plugins and enabling them
We move the logic to add or remove a plugin from the default ignore list to individual methods on the Plugin class (Plugin#enable, Plugin#disable) and use that when registering and parsing options. If the plugin is off-by-default, Plugin#register_options will use Plugin#disable. When parsing options via Plugin#provide_options, if the plugin has been specified in --enable-extensions then it will be re-enabled via Plugin#enable.
Diffstat (limited to 'flake8/plugins/manager.py')
-rw-r--r--flake8/plugins/manager.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/flake8/plugins/manager.py b/flake8/plugins/manager.py
index fe51391..dffc2f6 100644
--- a/flake8/plugins/manager.py
+++ b/flake8/plugins/manager.py
@@ -158,6 +158,14 @@ class Plugin(object):
LOG.critical(str(failed_to_load))
raise failed_to_load
+ def enable(self, optmanager):
+ """Remove plugin name from the default ignore list."""
+ optmanager.remove_from_default_ignore([self.name])
+
+ def disable(self, optmanager):
+ """Add the plugin name to the default ignore list."""
+ optmanager.extend_default_ignore([self.name])
+
def provide_options(self, optmanager, options, extra_args):
"""Pass the parsed options and extra arguments to the plugin."""
parse_options = getattr(self.plugin, 'parse_options', None)
@@ -168,6 +176,9 @@ class Plugin(object):
except TypeError:
parse_options(options)
+ if self.name in options.enable_extensions:
+ self.enable(optmanager)
+
def register_options(self, optmanager):
"""Register the plugin's command-line options on the OptionManager.
@@ -187,7 +198,7 @@ class Plugin(object):
add_options(optmanager)
if self.off_by_default:
- optmanager.extend_default_ignore([self.name])
+ self.disable(optmanager)
class PluginManager(object): # pylint: disable=too-few-public-methods