mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Allow loading of "builtin" plugins, even if "plugins" are not explicitly loaded
This commit is contained in:
@ -7,7 +7,6 @@ The main code for plugin special sauce is in the plugin registry in `InvenTree/p
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.conf import settings
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from maintenance_mode.core import set_maintenance_mode
|
from maintenance_mode.core import set_maintenance_mode
|
||||||
@ -26,7 +25,6 @@ class PluginAppConfig(AppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
"""The ready method is extended to initialize plugins."""
|
"""The ready method is extended to initialize plugins."""
|
||||||
if settings.PLUGINS_ENABLED:
|
|
||||||
if not canAppAccessDatabase(allow_test=True, allow_plugins=True):
|
if not canAppAccessDatabase(allow_test=True, allow_plugins=True):
|
||||||
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
||||||
else:
|
else:
|
||||||
@ -52,8 +50,9 @@ class PluginAppConfig(AppConfig):
|
|||||||
|
|
||||||
# check git version
|
# check git version
|
||||||
registry.git_is_modern = check_git_version()
|
registry.git_is_modern = check_git_version()
|
||||||
|
|
||||||
if not registry.git_is_modern: # pragma: no cover # simulating old git seems not worth it for coverage
|
if not registry.git_is_modern: # pragma: no cover # simulating old git seems not worth it for coverage
|
||||||
log_error(_('Your enviroment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load')
|
log_error(_('Your environment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info("Plugins not enabled - skipping loading sequence") # pragma: no cover
|
logger.info("Plugins not enabled - skipping loading sequence") # pragma: no cover
|
||||||
|
@ -106,6 +106,11 @@ class MetaBase:
|
|||||||
|
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
"""Return True if this plugin is currently active."""
|
"""Return True if this plugin is currently active."""
|
||||||
|
|
||||||
|
# Builtin plugins are always considered "active"
|
||||||
|
if self.is_builtin():
|
||||||
|
return True
|
||||||
|
|
||||||
cfg = self.plugin_config()
|
cfg = self.plugin_config()
|
||||||
|
|
||||||
if cfg:
|
if cfg:
|
||||||
@ -300,6 +305,16 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
|
|||||||
"""Is this plugin part of the samples?"""
|
"""Is this plugin part of the samples?"""
|
||||||
return self.check_is_sample()
|
return self.check_is_sample()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def check_is_builtin(cls) -> bool:
|
||||||
|
"""Determine if a particular plugin class is a 'builtin' plugin"""
|
||||||
|
return str(cls.check_package_path()).startswith('plugin/builtin')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_builtin(self) -> bool:
|
||||||
|
"""Is this plugin is builtin"""
|
||||||
|
return self.check_is_builtin()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_package_path(cls):
|
def check_package_path(cls):
|
||||||
"""Path to the plugin."""
|
"""Path to the plugin."""
|
||||||
|
@ -108,9 +108,6 @@ class PluginsRegistry:
|
|||||||
Args:
|
Args:
|
||||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||||
"""
|
"""
|
||||||
if not settings.PLUGINS_ENABLED:
|
|
||||||
# Plugins not enabled, do nothing
|
|
||||||
return # pragma: no cover
|
|
||||||
|
|
||||||
logger.info('Start loading plugins')
|
logger.info('Start loading plugins')
|
||||||
|
|
||||||
@ -167,9 +164,6 @@ class PluginsRegistry:
|
|||||||
|
|
||||||
def unload_plugins(self):
|
def unload_plugins(self):
|
||||||
"""Unload and deactivate all IntegrationPlugins."""
|
"""Unload and deactivate all IntegrationPlugins."""
|
||||||
if not settings.PLUGINS_ENABLED:
|
|
||||||
# Plugins not enabled, do nothing
|
|
||||||
return # pragma: no cover
|
|
||||||
|
|
||||||
logger.info('Start unloading plugins')
|
logger.info('Start unloading plugins')
|
||||||
|
|
||||||
@ -187,6 +181,7 @@ class PluginsRegistry:
|
|||||||
# remove maintenance
|
# remove maintenance
|
||||||
if not _maintenance:
|
if not _maintenance:
|
||||||
set_maintenance_mode(False) # pragma: no cover
|
set_maintenance_mode(False) # pragma: no cover
|
||||||
|
|
||||||
logger.info('Finished unloading plugins')
|
logger.info('Finished unloading plugins')
|
||||||
|
|
||||||
def reload_plugins(self, full_reload: bool = False):
|
def reload_plugins(self, full_reload: bool = False):
|
||||||
@ -210,8 +205,12 @@ class PluginsRegistry:
|
|||||||
def plugin_dirs(self):
|
def plugin_dirs(self):
|
||||||
"""Construct a list of directories from where plugins can be loaded"""
|
"""Construct a list of directories from where plugins can be loaded"""
|
||||||
|
|
||||||
|
# Builtin plugins are *always* loaded
|
||||||
dirs = ['plugin.builtin', ]
|
dirs = ['plugin.builtin', ]
|
||||||
|
|
||||||
|
if settings.PLUGINS_ENABLED:
|
||||||
|
# Any 'external' plugins are only loaded if PLUGINS_ENABLED is set to True
|
||||||
|
|
||||||
if settings.TESTING or settings.DEBUG:
|
if settings.TESTING or settings.DEBUG:
|
||||||
# If in TEST or DEBUG mode, load plugins from the 'samples' directory
|
# If in TEST or DEBUG mode, load plugins from the 'samples' directory
|
||||||
dirs.append('plugin.samples')
|
dirs.append('plugin.samples')
|
||||||
@ -263,9 +262,6 @@ class PluginsRegistry:
|
|||||||
|
|
||||||
def collect_plugins(self):
|
def collect_plugins(self):
|
||||||
"""Collect plugins from all possible ways of loading. Returned as list."""
|
"""Collect plugins from all possible ways of loading. Returned as list."""
|
||||||
if not settings.PLUGINS_ENABLED:
|
|
||||||
# Plugins not enabled, do nothing
|
|
||||||
return # pragma: no cover
|
|
||||||
|
|
||||||
collected_plugins = []
|
collected_plugins = []
|
||||||
|
|
||||||
@ -293,6 +289,9 @@ class PluginsRegistry:
|
|||||||
if modules:
|
if modules:
|
||||||
[collected_plugins.append(item) for item in modules]
|
[collected_plugins.append(item) for item in modules]
|
||||||
|
|
||||||
|
# From this point any plugins are considered "external" and only loaded if plugins are explicitly enabled
|
||||||
|
if settings.PLUGINS_ENABLED:
|
||||||
|
|
||||||
# Check if not running in testing mode and apps should be loaded from hooks
|
# Check if not 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):
|
||||||
# Collect plugins from setup entry points
|
# Collect plugins from setup entry points
|
||||||
|
Reference in New Issue
Block a user