Example #1
0
 def find_modules(self, exclude_dirs):
     basepath = osp.dirname(self.code_dir)
     basedir = osp.basename(basepath) + osp.sep
     if basedir not in sys.path:
         sys.path.insert(1, basedir)
     for filepath in globfind(self.code_dir, '*.py', exclude_dirs):
         if osp.basename(filepath) in ('setup.py', '__pkginfo__.py'):
             continue
         try:
             module = load_module_from_file(filepath)
         except: # module might be broken or magic
             dotted_path = modpath_from_file(filepath)
             module = type('.'.join(dotted_path), (), {}) # mock it
         yield module
Example #2
0
 def find_modules(self, exclude_dirs):
     basepath = osp.dirname(self.code_dir)
     basedir = osp.basename(basepath) + osp.sep
     if basedir not in sys.path:
         sys.path.insert(1, basedir)
     for filepath in globfind(self.code_dir, '*.py', exclude_dirs):
         if osp.basename(filepath) in ('setup.py', '__pkginfo__.py'):
             continue
         try:
             module = load_module_from_file(filepath)
         except: # module might be broken or magic
             dotted_path = modpath_from_file(filepath)
             module = type('.'.join(dotted_path), (), {}) # mock it
         yield module
Example #3
0
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):
        base, extension = 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))):
            try:
                module = load_module_from_file(join(directory, filename))
            except ValueError:
                # empty module name (usually emacs auto-save files)
                continue
            except ImportError, exc:
                print >> sys.stderr, "Problem importing module %s: %s" % (filename, exc)
            else:
                if hasattr(module, "register"):
                    module.register(linter)
                    imported[base] = 1
Example #4
0
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):
        base, extension = 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))):
            try:
                module = load_module_from_file(join(directory, filename))
            except ValueError:
                # empty module name (usually emacs auto-save files)
                continue
            except ImportError, exc:
                print >> sys.stderr, "Problem importing module %s: %s" % (filename, exc)
            else:
                if hasattr(module, 'register'):
                    module.register(linter)
                    imported[base] = 1