Skip to content
Snippets Groups Projects
Commit 38a489cb authored by Ashley Whetter's avatar Ashley Whetter
Browse files

WIP move command line parsing

parent 626b2219
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -79,15 +79,10 @@ class BaseChecker(OptionsProviderMixIn):
# mark this checker as enabled or not.
enabled = True
 
def __init__(self, linter=None):
"""checker instances should have the linter as argument
linter is an object implementing ILinter
"""
self.name = self.name.lower()
OptionsProviderMixIn.__init__(self)
self.linter = linter
def __init__(self):
super(BaseChecker, self).__init__()
 
# TODO: Remove
def add_message(self, msg_id, line=None, node=None, args=None, confidence=UNDEFINED):
"""add a message of a given type"""
self.linter.add_message(msg_id, line, node, args, confidence)
Loading
Loading
@@ -109,8 +104,12 @@ class BaseTokenChecker(BaseChecker):
raise NotImplementedError()
 
 
def initialize(linter):
"""initialize linter with checkers in this package """
register_plugins(linter, __path__[0])
def initialize(registry):
"""Register the checkers in this package.
Args:
registry (CheckerRegistry): The registry to register the checkers with.
"""
register_plugins(registry, __path__[0])
 
__all__ = ('BaseChecker', 'initialize')
This diff is collapsed.
This diff is collapsed.
Loading
Loading
@@ -1041,29 +1041,39 @@ class PyLintASTWalker(object):
 
PY_EXTS = ('.py', '.pyc', '.pyo', '.pyw', '.so', '.dll')
 
def register_plugins(linter, directory):
"""load all module and package in the given directory, looking for a
'register' function in each one, used to register pylint checkers
def register_plugins(registry, directory):
"""Load plugins from all modules and packages in the given directory.
Args:
registry (CheckerRegistry): The registry to register the checkers with.
directory (str): The directory to search for plugins.
"""
imported = {}
imported = set()
for filename in os.listdir(directory):
base, extension = splitext(filename)
base, extension = os.path.splitext(filename)
if base in imported or base == '__pycache__':
continue
if extension in PY_EXTS and base != '__init__' or (
not extension and isdir(join(directory, base))):
if extensions not in PY_EXTS or base == '__init__':
continue
package_dir = os.path.join(directory, base)
if not extension and os.path.isdir(package_dir):
file_path = os.path.join(directory, filename)
try:
module = modutils.load_module_from_file(join(directory, filename))
module = modutils.load_module_from_file(file_path)
except ValueError:
# empty module name (usually emacs auto-save files)
# Empty module name
continue
except ImportError as exc:
print("Problem importing module %s: %s" % (filename, exc),
file=sys.stderr)
else:
if hasattr(module, 'register'):
module.register(linter)
imported[base] = 1
module.register(registry)
imported.add(base)
 
def get_global_option(checker, option, default=None):
""" Retrieve an option defined by the given *checker* or
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment