mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
move import of integration plugins into registry
This commit is contained in:
parent
06e5430948
commit
7a65520252
@ -881,8 +881,6 @@ if not TESTING:
|
|||||||
if DEBUG or TESTING:
|
if DEBUG or TESTING:
|
||||||
PLUGIN_DIRS.append('plugin.samples')
|
PLUGIN_DIRS.append('plugin.samples')
|
||||||
|
|
||||||
PLUGINS = []
|
|
||||||
|
|
||||||
# Test settings
|
# Test settings
|
||||||
PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin
|
PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin
|
||||||
PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False)
|
PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False)
|
||||||
|
@ -81,7 +81,7 @@ def get_plugins(pkg, baseclass, recursive: bool = False):
|
|||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
|
|
||||||
def load_plugins(name: str, cls, module=None):
|
def load_plugins(name: str, cls, module):
|
||||||
"""general function to load a plugin class
|
"""general function to load a plugin class
|
||||||
|
|
||||||
:param name: name of the plugin for logs
|
: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
|
:param module: module from which the plugins should be loaded
|
||||||
:return: class of the to-be-loaded plugin
|
:return: class of the to-be-loaded plugin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logger.debug("Loading %s plugins", name)
|
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:
|
if len(plugins) > 0:
|
||||||
logger.info("Discovered %i %s plugins:", len(plugins), name)
|
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 a list of all registered action plugins
|
||||||
"""
|
"""
|
||||||
return load_plugins('action', ActionPlugin, module=action)
|
return load_plugins('action', ActionPlugin, action)
|
||||||
|
|
||||||
|
|
||||||
def load_integration_plugins():
|
|
||||||
"""
|
|
||||||
Return a list of all registered integration plugins
|
|
||||||
"""
|
|
||||||
return load_plugins('integration', IntegrationPluginBase)
|
|
||||||
|
|
||||||
|
|
||||||
def load_barcode_plugins():
|
def load_barcode_plugins():
|
||||||
@ -124,4 +116,4 @@ def load_barcode_plugins():
|
|||||||
from barcodes import plugins as BarcodePlugins
|
from barcodes import plugins as BarcodePlugins
|
||||||
from barcodes.barcode import BarcodePlugin
|
from barcodes.barcode import BarcodePlugin
|
||||||
|
|
||||||
return load_plugins('barcode', BarcodePlugin, module=BarcodePlugins)
|
return load_plugins('barcode', BarcodePlugin, BarcodePlugins)
|
||||||
|
@ -39,6 +39,8 @@ class Plugins:
|
|||||||
self.plugins = {}
|
self.plugins = {}
|
||||||
self.plugins_inactive = {}
|
self.plugins_inactive = {}
|
||||||
|
|
||||||
|
self.plugin_modules = [] # Holds all discovered plugins
|
||||||
|
|
||||||
self.errors = {} # Holds discovering errors
|
self.errors = {} # Holds discovering errors
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
@ -125,7 +127,7 @@ class Plugins:
|
|||||||
for plugin in settings.PLUGIN_DIRS:
|
for plugin in settings.PLUGIN_DIRS:
|
||||||
modules = inventree_plugins.get_plugins(importlib.import_module(plugin), IntegrationPluginBase, True)
|
modules = inventree_plugins.get_plugins(importlib.import_module(plugin), IntegrationPluginBase, True)
|
||||||
if modules:
|
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
|
# 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):
|
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', []):
|
for entry in metadata.entry_points().get('inventree_plugins', []):
|
||||||
plugin = entry.load()
|
plugin = entry.load()
|
||||||
plugin.is_package = True
|
plugin.is_package = True
|
||||||
settings.PLUGINS.append(plugin)
|
self.plugin_modules.append(plugin)
|
||||||
|
|
||||||
# Log found plugins
|
# Log collected plugins
|
||||||
logger.info(f'Found {len(settings.PLUGINS)} plugins!')
|
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
||||||
logger.info(", ".join([a.__module__ for a in settings.PLUGINS]))
|
logger.info(", ".join([a.__module__ for a in self.plugin_modules]))
|
||||||
|
|
||||||
def _init_plugins(self, disabled=None):
|
def _init_plugins(self, disabled=None):
|
||||||
"""initialise all found plugins
|
"""initialise all found plugins
|
||||||
@ -151,7 +153,7 @@ class Plugins:
|
|||||||
|
|
||||||
logger.info('Starting plugin initialisation')
|
logger.info('Starting plugin initialisation')
|
||||||
# Initialize integration plugins
|
# Initialize integration plugins
|
||||||
for plugin in inventree_plugins.load_integration_plugins():
|
for plugin in self.plugin_modules:
|
||||||
# check if package
|
# check if package
|
||||||
was_packaged = getattr(plugin, 'is_package', False)
|
was_packaged = getattr(plugin, 'is_package', False)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user