Remove unused and broken flake8.listen plugin type

This commit is contained in:
Anthony Sottile 2018-12-27 16:55:15 -08:00
parent 6ad56f73da
commit be88d26396
11 changed files with 19 additions and 525 deletions

View file

@ -57,14 +57,10 @@ class Application(object):
self.local_plugins = None
#: The instance of :class:`flake8.plugins.manager.Checkers`
self.check_plugins = None
#: The instance of :class:`flake8.plugins.manager.Listeners`
self.listening_plugins = None
#: The instance of :class:`flake8.plugins.manager.ReportFormatters`
self.formatting_plugins = None
#: The user-selected formatter from :attr:`formatting_plugins`
self.formatter = None
#: The :class:`flake8.plugins.notifier.Notifier` for listening plugins
self.listener_trie = None
#: The :class:`flake8.style_guide.StyleGuideManager` built from the
#: user's options
self.guide = None
@ -166,11 +162,11 @@ class Application(object):
# type: () -> NoneType
"""Find and load the plugins for this application.
If :attr:`check_plugins`, :attr:`listening_plugins`, or
:attr:`formatting_plugins` are ``None`` then this method will update
them with the appropriate plugin manager 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``.
If :attr:`check_plugins`, or :attr:`formatting_plugins` are ``None``
then this method will update them with the appropriate plugin manager
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``.
"""
if self.local_plugins is None:
self.local_plugins = config.get_local_plugins(
@ -186,16 +182,12 @@ class Application(object):
self.local_plugins.extension
)
if self.listening_plugins is None:
self.listening_plugins = plugin_manager.Listeners()
if self.formatting_plugins is None:
self.formatting_plugins = plugin_manager.ReportFormatters(
self.local_plugins.report
)
self.check_plugins.load_plugins()
self.listening_plugins.load_plugins()
self.formatting_plugins.load_plugins()
def register_plugin_options(self):
@ -203,7 +195,6 @@ class Application(object):
"""Register options provided by plugins to our option manager."""
self.check_plugins.register_options(self.option_manager)
self.check_plugins.register_plugin_versions(self.option_manager)
self.listening_plugins.register_options(self.option_manager)
self.formatting_plugins.register_options(self.option_manager)
def parse_configuration_and_cli(self, argv=None):
@ -229,9 +220,6 @@ class Application(object):
self.check_plugins.provide_options(
self.option_manager, self.options, self.args
)
self.listening_plugins.provide_options(
self.option_manager, self.options, self.args
)
self.formatting_plugins.provide_options(
self.option_manager, self.options, self.args
)
@ -264,18 +252,12 @@ class Application(object):
self.formatter = formatter_class(self.options)
def make_notifier(self):
# type: () -> NoneType
"""Initialize our listener Notifier."""
if self.listener_trie is None:
self.listener_trie = self.listening_plugins.build_notifier()
def make_guide(self):
# type: () -> NoneType
"""Initialize our StyleGuide."""
if self.guide is None:
self.guide = style_guide.StyleGuideManager(
self.options, self.listener_trie, self.formatter
self.options, self.formatter
)
if self.running_against_diff:
@ -373,7 +355,6 @@ class Application(object):
self.register_plugin_options()
self.parse_configuration_and_cli(argv)
self.make_formatter()
self.make_notifier()
self.make_guide()
self.make_file_checker_manager()

View file

@ -1,95 +0,0 @@
"""Independent implementation of a Trie tree."""
__all__ = ("Trie", "TrieNode")
def _iterate_stringlike_objects(string):
for i in range(len(string)):
yield string[i : i + 1]
class Trie(object):
"""The object that manages the trie nodes."""
def __init__(self):
"""Initialize an empty trie."""
self.root = TrieNode(None, None)
def add(self, path, node_data):
"""Add the node data to the path described."""
node = self.root
for prefix in _iterate_stringlike_objects(path):
child = node.find_prefix(prefix)
if child is None:
child = node.add_child(prefix, [])
node = child
node.data.append(node_data)
def find(self, path):
"""Find a node based on the path provided."""
node = self.root
for prefix in _iterate_stringlike_objects(path):
child = node.find_prefix(prefix)
if child is None:
return None
node = child
return node
def traverse(self):
"""Traverse this tree.
This performs a depth-first pre-order traversal of children in this
tree. It returns the results consistently by first sorting the
children based on their prefix and then traversing them in
alphabetical order.
"""
return self.root.traverse()
class TrieNode(object):
"""The majority of the implementation details of a Trie."""
def __init__(self, prefix, data, children=None):
"""Initialize a TrieNode with data and children."""
self.children = children or {}
self.data = data
self.prefix = prefix
def __repr__(self):
"""Generate an easy to read representation of the node."""
return "TrieNode(prefix={0}, data={1})".format(self.prefix, self.data)
def find_prefix(self, prefix):
"""Find the prefix in the children of this node.
:returns: A child matching the prefix or None.
:rtype: :class:`~TrieNode` or None
"""
return self.children.get(prefix, None)
def add_child(self, prefix, data, children=None):
"""Create and add a new child node.
:returns: The newly created node
:rtype: :class:`~TrieNode`
"""
new_node = TrieNode(prefix, data, children)
self.children[prefix] = new_node
return new_node
def traverse(self):
"""Traverse children of this node.
This performs a depth-first pre-order traversal of the remaining
children in this sub-tree. It returns the results consistently by
first sorting the children based on their prefix and then traversing
them in alphabetical order.
"""
if not self.children:
return
for prefix in sorted(self.children):
child = self.children[prefix]
yield child
for child in child.traverse():
yield child

View file

@ -6,7 +6,6 @@ import entrypoints
from flake8 import exceptions
from flake8 import utils
from flake8.plugins import notifier
if sys.version_info >= (3, 3):
import collections.abc as collections_abc
@ -15,13 +14,7 @@ else:
LOG = logging.getLogger(__name__)
__all__ = (
"Checkers",
"Listeners",
"Plugin",
"PluginManager",
"ReportFormatters",
)
__all__ = ("Checkers", "Plugin", "PluginManager", "ReportFormatters")
NO_GROUP_FOUND = object()
@ -444,24 +437,6 @@ class PluginTypeManager(object):
list(self.manager.map(call_provide_options))
class NotifierBuilderMixin(object): # pylint: disable=too-few-public-methods
"""Mixin class that builds a Notifier from a PluginManager."""
def build_notifier(self):
"""Build a Notifier for our Listeners.
:returns:
Object to notify our listeners of certain error codes and
warnings.
:rtype:
:class:`~flake8.notifier.Notifier`
"""
notifier_trie = notifier.Notifier()
for name in self.names:
notifier_trie.register_listener(name, self.manager[name])
return notifier_trie
class Checkers(PluginTypeManager):
"""All of the checkers registered through entry-points or config."""
@ -542,12 +517,6 @@ class Checkers(PluginTypeManager):
return plugins
class Listeners(PluginTypeManager, NotifierBuilderMixin):
"""All of the listeners registered through entry-points or config."""
namespace = "flake8.listen"
class ReportFormatters(PluginTypeManager):
"""All of the report formatters registered through entry-points/config."""

View file

@ -1,46 +0,0 @@
"""Implementation of the class that registers and notifies listeners."""
from flake8.plugins import _trie
class Notifier(object):
"""Object that tracks and notifies listener objects."""
def __init__(self):
"""Initialize an empty notifier object."""
self.listeners = _trie.Trie()
def listeners_for(self, error_code):
"""Retrieve listeners for an error_code.
There may be listeners registered for E1, E100, E101, E110, E112, and
E126. To get all the listeners for one of E100, E101, E110, E112, or
E126 you would also need to incorporate the listeners for E1 (since
they're all in the same class).
Example usage:
.. code-block:: python
from flake8 import notifier
n = notifier.Notifier()
# register listeners
for listener in n.listeners_for('W102'):
listener.notify(...)
"""
path = error_code
while path:
node = self.listeners.find(path)
listeners = getattr(node, "data", [])
for listener in listeners:
yield listener
path = path[:-1]
def notify(self, error_code, *args, **kwargs):
"""Notify all listeners for the specified error code."""
for listener in self.listeners_for(error_code):
listener.notify(error_code, *args, **kwargs)
def register_listener(self, error_code, listener):
"""Register a listener for a specific error_code."""
self.listeners.add(error_code, listener)

View file

@ -325,19 +325,18 @@ class DecisionEngine(object):
class StyleGuideManager(object):
"""Manage multiple style guides for a single run."""
def __init__(self, options, listener_trie, formatter, decider=None):
def __init__(self, options, formatter, decider=None):
"""Initialize our StyleGuide.
.. todo:: Add parameter documentation.
"""
self.options = options
self.listener = listener_trie
self.formatter = formatter
self.stats = statistics.Statistics()
self.decider = decider or DecisionEngine(options)
self.style_guides = []
self.default_style_guide = StyleGuide(
options, listener_trie, formatter, decider=decider
options, formatter, decider=decider
)
self.style_guides = list(
itertools.chain(
@ -435,15 +434,12 @@ class StyleGuideManager(object):
class StyleGuide(object):
"""Manage a Flake8 user's style guide."""
def __init__(
self, options, listener_trie, formatter, filename=None, decider=None
):
def __init__(self, options, formatter, filename=None, decider=None):
"""Initialize our StyleGuide.
.. todo:: Add parameter documentation.
"""
self.options = options
self.listener = listener_trie
self.formatter = formatter
self.stats = statistics.Statistics()
self.decider = decider or DecisionEngine(options)
@ -461,9 +457,7 @@ class StyleGuide(object):
filename = filename or self.filename
options = copy.deepcopy(self.options)
options.ignore.extend(extend_ignore_with or [])
return StyleGuide(
options, self.listener, self.formatter, filename=filename
)
return StyleGuide(options, self.formatter, filename=filename)
@contextlib.contextmanager
def processing_file(self, filename):
@ -565,7 +559,6 @@ class StyleGuide(object):
):
self.formatter.handle(error)
self.stats.record(error)
self.listener.notify(error.code, error)
return 1
return 0