Hardcode the "plugins" package name

This commit is contained in:
Tobias Gruetzmacher 2020-10-01 21:20:08 +02:00
parent 9237bd62b2
commit 3256f9fdc2
2 changed files with 9 additions and 8 deletions

View file

@ -1,26 +1,27 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# Copyright (C) 2012-2014 Bastian Kleineidam # Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2016-2019 Tobias Gruetzmacher # Copyright (C) 2016-2020 Tobias Gruetzmacher
""" """
Functions to load plugin modules. Functions to load plugin modules.
Example usage: Example usage:
modules = loader.get_modules('plugins') modules = loader.get_plugin_modules()
plugins = loader.get_plugins(modules, PluginClass) plugins = loader.get_plugins(modules, PluginClass)
""" """
import importlib import importlib
import pkgutil import pkgutil
from .plugins import (__name__ as plugin_package, __path__ as plugin_path)
from .output import out from .output import out
def get_modules(folder): def get_plugin_modules():
"""Find (and import) all valid modules in the given submodule of this file. """Find (and import) all valid modules in the "plugins" package.
@return: all loaded valid modules @return: all loaded valid modules
@rtype: iterator of module @rtype: iterator of module
""" """
mod = importlib.import_module(".." + folder, __name__) prefix = plugin_package + "."
prefix = mod.__name__ + "." modules = [m[1] for m in pkgutil.iter_modules(plugin_path, prefix)]
modules = [m[1] for m in pkgutil.iter_modules(mod.__path__, prefix)]
for elm in _get_all_modules_pyinstaller(): for elm in _get_all_modules_pyinstaller():
if elm.startswith(prefix): if elm.startswith(prefix):

View file

@ -574,7 +574,7 @@ class Cache:
def load(self): def load(self):
out.debug("Loading comic modules...") out.debug("Loading comic modules...")
modules = loader.get_modules('plugins') modules = loader.get_plugin_modules()
plugins = list(loader.get_plugins(modules, Scraper)) plugins = list(loader.get_plugins(modules, Scraper))
self.data = list([m for x in plugins for m in x.getmodules()]) self.data = list([m for x in plugins for m in x.getmodules()])
self.validate() self.validate()