From 7a65520252d8f4c969d4b5b5729a642fe1f3e8b7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 19:25:40 +0100 Subject: [PATCH] move import of integration plugins into registry --- InvenTree/InvenTree/settings.py | 2 -- InvenTree/plugin/plugins.py | 16 ++++------------ InvenTree/plugin/registry.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 724ff26c7c..030ea1d5ae 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -881,8 +881,6 @@ if not TESTING: if DEBUG or TESTING: PLUGIN_DIRS.append('plugin.samples') -PLUGINS = [] - # Test settings PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False) diff --git a/InvenTree/plugin/plugins.py b/InvenTree/plugin/plugins.py index 2827ec590c..79971e49a6 100644 --- a/InvenTree/plugin/plugins.py +++ b/InvenTree/plugin/plugins.py @@ -81,7 +81,7 @@ def get_plugins(pkg, baseclass, recursive: bool = False): return plugins -def load_plugins(name: str, cls, module=None): +def load_plugins(name: str, cls, module): """general function to load a plugin class :param name: name of the plugin for logs @@ -89,10 +89,9 @@ def load_plugins(name: str, cls, module=None): :param module: module from which the plugins should be loaded :return: class of the to-be-loaded plugin """ - logger.debug("Loading %s plugins", name) - plugins = get_plugins(module, cls) if module else settings.PLUGINS + plugins = get_plugins(module, cls) if len(plugins) > 0: logger.info("Discovered %i %s plugins:", len(plugins), name) @@ -107,14 +106,7 @@ def load_action_plugins(): """ Return a list of all registered action plugins """ - return load_plugins('action', ActionPlugin, module=action) - - -def load_integration_plugins(): - """ - Return a list of all registered integration plugins - """ - return load_plugins('integration', IntegrationPluginBase) + return load_plugins('action', ActionPlugin, action) def load_barcode_plugins(): @@ -124,4 +116,4 @@ def load_barcode_plugins(): from barcodes import plugins as BarcodePlugins from barcodes.barcode import BarcodePlugin - return load_plugins('barcode', BarcodePlugin, module=BarcodePlugins) + return load_plugins('barcode', BarcodePlugin, BarcodePlugins) diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4a78debaa9..d026662f7c 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -39,6 +39,8 @@ class Plugins: self.plugins = {} self.plugins_inactive = {} + self.plugin_modules = [] # Holds all discovered plugins + self.errors = {} # Holds discovering errors # flags @@ -125,7 +127,7 @@ class Plugins: for plugin in settings.PLUGIN_DIRS: modules = inventree_plugins.get_plugins(importlib.import_module(plugin), IntegrationPluginBase, True) if modules: - [settings.PLUGINS.append(item) for item in modules] + [self.plugin_modules.append(item) for item in modules] # check if running in testing mode and apps should be loaded from hooks if (not settings.PLUGIN_TESTING) or (settings.PLUGIN_TESTING and settings.PLUGIN_TESTING_SETUP): @@ -133,11 +135,11 @@ class Plugins: for entry in metadata.entry_points().get('inventree_plugins', []): plugin = entry.load() plugin.is_package = True - settings.PLUGINS.append(plugin) + self.plugin_modules.append(plugin) - # Log found plugins - logger.info(f'Found {len(settings.PLUGINS)} plugins!') - logger.info(", ".join([a.__module__ for a in settings.PLUGINS])) + # Log collected plugins + logger.info(f'Collected {len(self.plugin_modules)} plugins!') + logger.info(", ".join([a.__module__ for a in self.plugin_modules])) def _init_plugins(self, disabled=None): """initialise all found plugins @@ -151,7 +153,7 @@ class Plugins: logger.info('Starting plugin initialisation') # Initialize integration plugins - for plugin in inventree_plugins.load_integration_plugins(): + for plugin in self.plugin_modules: # check if package was_packaged = getattr(plugin, 'is_package', False)