diff options
| author | Torsten Marek <tmarek@google.com> | 2013-06-19 16:29:18 +0200 | 
|---|---|---|
| committer | Torsten Marek <tmarek@google.com> | 2013-06-19 16:29:18 +0200 | 
| commit | 814d6a1f873afd3676dae7b4edaa38a087a06159 (patch) | |
| tree | 7601f098058d29ad157b6cb6e6f071e473561b9b /utils.py | |
| parent | 8e5200e40cf865e9cd55bb9f9292eef3b04ac012 (diff) | |
| download | pylint-git-814d6a1f873afd3676dae7b4edaa38a087a06159.tar.gz | |
Turn reporters into proper plugins rather than classes that are loaded explicitly.
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 31 | 
1 files changed, 30 insertions, 1 deletions
| @@ -21,11 +21,12 @@ import re  import sys  import tokenize  from warnings import warn +import os  from os.path import dirname, basename, splitext, exists, isdir, join, normpath  from logilab.common.interface import implements  from logilab.common.modutils import modpath_from_file, get_module_files, \ -                                    file_from_modpath +                                    file_from_modpath, load_module_from_file  from logilab.common.textutils import normalize_text  from logilab.common.configuration import rest_format_section  from logilab.common.ureports import Section @@ -42,6 +43,7 @@ class EmptyReport(Exception):      """raised when a report is empty and so should not be displayed""" +  MSG_TYPES = {      'I' : 'info',      'C' : 'convention', @@ -653,3 +655,30 @@ class PyLintASTWalker(object):              self.walk(child)          for cb in self.leave_events.get(cid, ()):              cb(astroid) + + +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 +    """ +    imported = {} +    for filename in os.listdir(directory): +        basename, extension = os.path.splitext(filename) +        if basename in imported or basename == '__pycache__': +            continue +        if extension in PY_EXTS and basename != '__init__' or ( +             not extension and os.isdir(os.path.join(directory, basename))): +            try: +                module = load_module_from_file(os.path.join(directory, filename)) +            except ValueError: +                # empty module name (usually emacs auto-save files) +                continue +            except ImportError, exc: +                import sys +                print >> sys.stderr, "Problem importing module %s: %s" % (filename, exc) +            else: +                if hasattr(module, 'register'): +                    module.register(linter) +                    imported[basename] = 1 | 
