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