From 3256f9fdc27b09c80f79adc8b9ea4f711a3aba10 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Thu, 1 Oct 2020 21:20:08 +0200 Subject: [PATCH] Hardcode the "plugins" package name --- dosagelib/loader.py | 15 ++++++++------- dosagelib/scraper.py | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dosagelib/loader.py b/dosagelib/loader.py index bc7c6057d..2fcc67b96 100644 --- a/dosagelib/loader.py +++ b/dosagelib/loader.py @@ -1,26 +1,27 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2016-2019 Tobias Gruetzmacher +# Copyright (C) 2016-2020 Tobias Gruetzmacher """ Functions to load plugin modules. Example usage: - modules = loader.get_modules('plugins') + modules = loader.get_plugin_modules() plugins = loader.get_plugins(modules, PluginClass) """ import importlib import pkgutil + +from .plugins import (__name__ as plugin_package, __path__ as plugin_path) from .output import out -def get_modules(folder): - """Find (and import) all valid modules in the given submodule of this file. +def get_plugin_modules(): + """Find (and import) all valid modules in the "plugins" package. @return: all loaded valid modules @rtype: iterator of module """ - mod = importlib.import_module(".." + folder, __name__) - prefix = mod.__name__ + "." - modules = [m[1] for m in pkgutil.iter_modules(mod.__path__, prefix)] + prefix = plugin_package + "." + modules = [m[1] for m in pkgutil.iter_modules(plugin_path, prefix)] for elm in _get_all_modules_pyinstaller(): if elm.startswith(prefix): diff --git a/dosagelib/scraper.py b/dosagelib/scraper.py index 41402e62f..b881c9f23 100644 --- a/dosagelib/scraper.py +++ b/dosagelib/scraper.py @@ -574,7 +574,7 @@ class Cache: def load(self): out.debug("Loading comic modules...") - modules = loader.get_modules('plugins') + modules = loader.get_plugin_modules() plugins = list(loader.get_plugins(modules, Scraper)) self.data = list([m for x in plugins for m in x.getmodules()]) self.validate()