diff options
Diffstat (limited to 'pylint/utils.py')
-rw-r--r-- | pylint/utils.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/pylint/utils.py b/pylint/utils.py index 3f71cba67..513ed4666 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -1340,24 +1340,26 @@ class PyLintASTWalker: 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 = {"__init__", "__pycache__"} for filename in os.listdir(directory): - base, extension = splitext(filename) - if base in imported or base == "__pycache__": + base, extension = os.path.splitext(filename) + if base in imported: continue - if ( - extension in PY_EXTS - and base != "__init__" - or (not extension and isdir(join(directory, base))) - ): + + package_dir = os.path.join(directory, base) + if extension in PY_EXTS or (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( @@ -1365,8 +1367,8 @@ def register_plugins(linter, directory): ) 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): |