diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-12-28 15:39:49 +0000 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-12-28 15:39:49 +0000 |
| commit | 7f50c3acc4b98caff0d0f3fbd82de34c5fc93c8a (patch) | |
| tree | 31b08b45819030d11a6321b88416082756241cd1 /src/flake8/plugins | |
| parent | 6ad56f73daa1a23081ed40a409d53ef28bf53c3f (diff) | |
| parent | be88d2639694da77d07a9075231a0bea2b8df3f5 (diff) | |
| download | flake8-7f50c3acc4b98caff0d0f3fbd82de34c5fc93c8a.tar.gz | |
Merge branch 'remove_unused_broken_flake8_listen' into 'master'
Remove unused and broken flake8.listen plugin type
Closes #480
See merge request pycqa/flake8!274
Diffstat (limited to 'src/flake8/plugins')
| -rw-r--r-- | src/flake8/plugins/_trie.py | 95 | ||||
| -rw-r--r-- | src/flake8/plugins/manager.py | 33 | ||||
| -rw-r--r-- | src/flake8/plugins/notifier.py | 46 |
3 files changed, 1 insertions, 173 deletions
diff --git a/src/flake8/plugins/_trie.py b/src/flake8/plugins/_trie.py deleted file mode 100644 index 9a50b45..0000000 --- a/src/flake8/plugins/_trie.py +++ /dev/null @@ -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 diff --git a/src/flake8/plugins/manager.py b/src/flake8/plugins/manager.py index 411e02f..045cfd7 100644 --- a/src/flake8/plugins/manager.py +++ b/src/flake8/plugins/manager.py @@ -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.""" diff --git a/src/flake8/plugins/notifier.py b/src/flake8/plugins/notifier.py deleted file mode 100644 index 9efccd4..0000000 --- a/src/flake8/plugins/notifier.py +++ /dev/null @@ -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) |
