# HG changeset patch # User Goffi # Date 1600603540 -7200 # Node ID 2157880ba3b47f0d7f4905ecbc4926e16e72b637 # Parent 96b2f84a685cef084357bdd018e8a4540b617f9a core: plugins can now be loaded from a directory: A plugin can now be a directory with a name starting by `plugin_`. It will then be loaded as a module. The `__init__.py` file must contain the `PLUGIN_INFO` dict with metadata. diff -r 96b2f84a685c -r 2157880ba3b4 sat/core/sat_main.py --- a/sat/core/sat_main.py Sun Sep 20 14:05:40 2020 +0200 +++ b/sat/core/sat_main.py Sun Sep 20 14:05:40 2020 +0200 @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from glob import glob import sys import os.path import uuid @@ -273,17 +272,29 @@ # TODO: do not import all plugins if no needed: component plugins are not needed # if we just use a client, and plugin blacklisting should be possible in # sat.conf - plugins_path = os.path.dirname(sat.plugins.__file__) - plugin_glob = "plugin*." + C.PLUGIN_EXT - plug_lst = [ - os.path.splitext(plugin)[0] - for plugin in map( - os.path.basename, glob(os.path.join(plugins_path, plugin_glob)) - ) - ] + plugins_path = Path(sat.plugins.__file__).parent plugins_to_import = {} # plugins we still have to import - for plug in plug_lst: - plugin_path = "sat.plugins." + plug + for plug_path in plugins_path.glob("plugin_*"): + if plug_path.is_dir(): + init_path = plug_path / f"__init__.{C.PLUGIN_EXT}" + if not init_path.exists(): + log.warning( + f"{plug_path} doesn't appear to be a package, can't load it") + continue + plug_name = plug_path.name + elif plug_path.is_file(): + if plug_path.suffix != f".{C.PLUGIN_EXT}": + continue + plug_name = plug_path.stem + else: + log.warning( + f"{plug_path} is not a file or a dir, ignoring it") + continue + if not plug_name.isidentifier(): + log.warning( + f"{plug_name!r} is not a valid name for a plugin, ignoring it") + continue + plugin_path = f"sat.plugins.{plug_name}" try: __import__(plugin_path) except exceptions.MissingModule as e: