示例#1
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 = os.path.splitext(filename)
        if base in imported or base == "__pycache__":
            continue
        if (extension in PY_EXTS and base != "__init__" or
            (not extension and os.path.isdir(os.path.join(directory, base))
             and not filename.startswith("."))):
            try:
                module = modutils.load_module_from_file(
                    os.path.join(directory, filename))
            except ValueError:
                # empty module name (usually emacs auto-save files)
                continue
            except ImportError as exc:
                print(f"Problem importing module {filename}: {exc}",
                      file=sys.stderr)
            else:
                if hasattr(module, "register"):
                    module.register(linter)
                    imported[base] = 1
示例#2
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 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 = modutils.load_module_from_file(join(directory, filename))
            except ValueError:
                # empty module name (usually emacs auto-save files)
                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
示例#3
0
def register_hooks(parser: "elementparser.ElementParser", path: str) -> None:
    """ Load all modules in the given directory and look for modules
  with a 'register' function. This is used to register parser hooks
  
  Arguments:
      parser {elementparser.ElementParser} -- parser to register hooks
      path {str} -- Path of the directory
  """
    directory = Path(path)
    file_name_list = _get_module_list(directory)
    for f in file_name_list:
        try:
            module = modutils.load_module_from_file(directory / f)
        except ValueError:
            # empty module name
            continue
        except ImportError as e:
            print(f'Problem importing module {f}: {e}', file=sys.stderr)
        else:
            if hasattr(module, 'register'):
                module.register(parser)
示例#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 = modutils.load_module_from_file(join(directory, filename))
            except ValueError:
                # empty module name (usually emacs auto-save files)
                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