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

1"""Apps file for plugin app. 

2 

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""" 

6 

7from django.apps import AppConfig 

8 

9import structlog 

10from maintenance_mode.core import set_maintenance_mode 

11 

12from InvenTree.ready import ( 

13 canAppAccessDatabase, 

14 ignore_ready_warning, 

15 isInMainThread, 

16 isInWorkerThread, 

17) 

18from plugin import registry 

19 

20logger = structlog.get_logger('inventree') 

21 

22 

23class PluginAppConfig(AppConfig): 

24 """AppConfig for plugins.""" 

25 

26 name = 'plugin' 

27 

28 def ready(self): 

29 """The ready method is extended to initialize plugins.""" 

30 self.reload_plugin_registry() 

31 

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 

37 

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') 

44 

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() 

50 

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)