mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 18:56:53 +00:00
Add missing docstrings to plugin submodule
This commit is contained in:
parent
11be73dbbb
commit
83dd81a445
4 changed files with 24 additions and 0 deletions
|
|
@ -159,6 +159,7 @@ class OptionManager(object):
|
|||
|
||||
@staticmethod
|
||||
def format_plugin(plugin_tuple):
|
||||
"""Convert a plugin tuple into a dictionary mapping name to value."""
|
||||
return dict(zip(["entry", "name", "version"], plugin_tuple))
|
||||
|
||||
def add_option(self, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
"""Submodule of built-in plugins and plugin managers."""
|
||||
|
|
@ -6,6 +6,14 @@ import pkg_resources
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
__all__ = (
|
||||
'Checkers',
|
||||
'Listeners',
|
||||
'Plugin',
|
||||
'PluginManager',
|
||||
'ReportFormatters',
|
||||
)
|
||||
|
||||
|
||||
class Plugin(object):
|
||||
"""Wrap an EntryPoint from setuptools and other logic."""
|
||||
|
|
@ -25,17 +33,23 @@ class Plugin(object):
|
|||
self._plugin = None
|
||||
|
||||
def __repr__(self):
|
||||
"""Provide an easy to read description of the current plugin."""
|
||||
return 'Plugin(name="{0}", entry_point="{1}")'.format(
|
||||
self.name, self.entry_point
|
||||
)
|
||||
|
||||
@property
|
||||
def plugin(self):
|
||||
"""The loaded (and cached) plugin associated with the entry-point.
|
||||
|
||||
This property implicitly loads the plugin and then caches it.
|
||||
"""
|
||||
self.load_plugin()
|
||||
return self._plugin
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""Return the version attribute on the plugin."""
|
||||
return self.plugin.version
|
||||
|
||||
def execute(self, *args, **kwargs):
|
||||
|
|
@ -124,10 +138,12 @@ class PluginManager(object):
|
|||
self._load_all_plugins()
|
||||
|
||||
def __contains__(self, name):
|
||||
"""Check if the entry-point name is in this plugin manager."""
|
||||
LOG.debug('Checking for "%s" in plugin manager.', name)
|
||||
return name in self.plugins
|
||||
|
||||
def __getitem__(self, name):
|
||||
"""Retrieve a plugin by its entry-point name."""
|
||||
LOG.debug('Retrieving plugin for "%s".', name)
|
||||
return self.plugins[name]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
"""Plugin built-in to Flake8 to treat pyflakes as a plugin."""
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
try:
|
||||
|
|
@ -40,10 +41,12 @@ patch_pyflakes()
|
|||
|
||||
class FlakesChecker(pyflakes.checker.Checker):
|
||||
"""Subclass the Pyflakes checker to conform with the flake8 API."""
|
||||
|
||||
name = 'pyflakes'
|
||||
version = pyflakes.__version__
|
||||
|
||||
def __init__(self, tree, filename):
|
||||
"""Initialize the PyFlakes plugin with an AST tree and filename."""
|
||||
filename = utils.normalize_paths(filename)[0]
|
||||
withDoctest = self.withDoctest
|
||||
included_by = [include for include in self.include_in_doctest
|
||||
|
|
@ -65,6 +68,7 @@ class FlakesChecker(pyflakes.checker.Checker):
|
|||
|
||||
@classmethod
|
||||
def add_options(cls, parser):
|
||||
"""Register options for PyFlakes on the Flake8 OptionManager."""
|
||||
parser.add_option(
|
||||
'--builtins', parse_from_config=True, comma_separated_list=True,
|
||||
help="define more built-ins, comma separated",
|
||||
|
|
@ -91,6 +95,7 @@ class FlakesChecker(pyflakes.checker.Checker):
|
|||
|
||||
@classmethod
|
||||
def parse_options(cls, options):
|
||||
"""Parse option values from Flake8's OptionManager."""
|
||||
if options.builtins:
|
||||
cls.builtIns = cls.builtIns.union(options.builtins.split(','))
|
||||
cls.withDoctest = options.doctests
|
||||
|
|
@ -125,6 +130,7 @@ class FlakesChecker(pyflakes.checker.Checker):
|
|||
'both for doctesting.' % inc_exc)
|
||||
|
||||
def run(self):
|
||||
"""Run the plugin."""
|
||||
for m in self.messages:
|
||||
col = getattr(m, 'col', 0)
|
||||
yield m.lineno, col, (m.flake8_msg % m.message_args), m.__class__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue