Coverage for src/backend/InvenTree/plugin/apps.py: 85%
21 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Apps file for plugin app.
3This initializes the plugin mechanisms and handles reloading throughout the lifecycle.
4The main code for plugin special sauce is in the plugin registry in `InvenTree/plugin/registry.py`.
5"""
7from django.apps import AppConfig
9import structlog
10from maintenance_mode.core import set_maintenance_mode
12from InvenTree.ready import (
13 canAppAccessDatabase,
14 ignore_ready_warning,
15 isInMainThread,
16 isInWorkerThread,
17)
18from plugin import registry
20logger = structlog.get_logger('inventree')
23class PluginAppConfig(AppConfig):
24 """AppConfig for plugins."""
26 name = 'plugin'
28 def ready(self):
29 """The ready method is extended to initialize plugins."""
30 self.reload_plugin_registry()
32 @ignore_ready_warning
33 def reload_plugin_registry(self):
34 """Reload the plugin registry."""
35 if not isInMainThread() and not isInWorkerThread(): 35 ↛ 36line 35 didn't jump to line 36 because the condition on line 35 was never true
36 return
38 if not canAppAccessDatabase( 38 ↛ 41line 38 didn't jump to line 41 because the condition on line 38 was never true
39 allow_test=True, allow_plugins=True, allow_shell=True
40 ):
41 logger.info('Skipping plugin loading sequence') # pragma: no cover
42 else:
43 logger.info('Loading InvenTree plugins')
45 if not registry.is_ready:
46 # Mark the registry as ready
47 # This ensures that other apps cannot access the registry before it is fully initialized
48 logger.info('Plugin registry is ready - performing initial load')
49 registry.set_ready()
51 # drop out of maintenance
52 # makes sure we did not have an error in reloading and maintenance is still active
53 set_maintenance_mode(False)