mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Merge branch 'inventree:master' into fix-set_user
This commit is contained in:
@ -53,7 +53,7 @@ class InvenTreePluginBase():
|
||||
else:
|
||||
return self.plugin_name()
|
||||
|
||||
def plugin_config(self, raise_error=False):
|
||||
def plugin_config(self):
|
||||
"""
|
||||
Return the PluginConfig object associated with this plugin
|
||||
"""
|
||||
@ -65,12 +65,9 @@ class InvenTreePluginBase():
|
||||
key=self.plugin_slug(),
|
||||
name=self.plugin_name(),
|
||||
)
|
||||
except (OperationalError, ProgrammingError) as error:
|
||||
except (OperationalError, ProgrammingError):
|
||||
cfg = None
|
||||
|
||||
if raise_error:
|
||||
raise error
|
||||
|
||||
return cfg
|
||||
|
||||
def is_active(self):
|
||||
@ -91,6 +88,6 @@ class InvenTreePlugin(InvenTreePluginBase):
|
||||
"""
|
||||
This is here for leagcy reasons and will be removed in the next major release
|
||||
"""
|
||||
def __init__(self):
|
||||
def __init__(self): # pragma: no cover
|
||||
warnings.warn("Using the InvenTreePlugin is depreceated", DeprecationWarning)
|
||||
super().__init__()
|
||||
|
@ -21,7 +21,7 @@ from django.utils.text import slugify
|
||||
|
||||
try:
|
||||
from importlib import metadata
|
||||
except:
|
||||
except: # pragma: no cover
|
||||
import importlib_metadata as metadata
|
||||
# TODO remove when python minimum is 3.8
|
||||
|
||||
@ -84,7 +84,7 @@ class PluginsRegistry:
|
||||
"""
|
||||
if not settings.PLUGINS_ENABLED:
|
||||
# Plugins not enabled, do nothing
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
logger.info('Start loading plugins')
|
||||
|
||||
@ -120,7 +120,7 @@ class PluginsRegistry:
|
||||
# We do not want to end in an endless loop
|
||||
retry_counter -= 1
|
||||
|
||||
if retry_counter <= 0:
|
||||
if retry_counter <= 0: # pragma: no cover
|
||||
if settings.PLUGIN_TESTING:
|
||||
print('[PLUGIN] Max retries, breaking loading')
|
||||
# TODO error for server status
|
||||
@ -143,14 +143,14 @@ class PluginsRegistry:
|
||||
|
||||
if not settings.PLUGINS_ENABLED:
|
||||
# Plugins not enabled, do nothing
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
logger.info('Start unloading plugins')
|
||||
|
||||
# Set maintanace mode
|
||||
_maintenance = bool(get_maintenance_mode())
|
||||
if not _maintenance:
|
||||
set_maintenance_mode(True)
|
||||
set_maintenance_mode(True) # pragma: no cover
|
||||
|
||||
# remove all plugins from registry
|
||||
self._clean_registry()
|
||||
@ -160,7 +160,7 @@ class PluginsRegistry:
|
||||
|
||||
# remove maintenance
|
||||
if not _maintenance:
|
||||
set_maintenance_mode(False)
|
||||
set_maintenance_mode(False) # pragma: no cover
|
||||
logger.info('Finished unloading plugins')
|
||||
|
||||
def reload_plugins(self):
|
||||
@ -170,7 +170,7 @@ class PluginsRegistry:
|
||||
|
||||
# Do not reload whe currently loading
|
||||
if self.is_loading:
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
logger.info('Start reloading plugins')
|
||||
|
||||
@ -187,7 +187,7 @@ class PluginsRegistry:
|
||||
|
||||
if not settings.PLUGINS_ENABLED:
|
||||
# Plugins not enabled, do nothing
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
self.plugin_modules = [] # clear
|
||||
|
||||
@ -200,7 +200,7 @@ class PluginsRegistry:
|
||||
# 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):
|
||||
# Collect plugins from setup entry points
|
||||
for entry in metadata.entry_points().get('inventree_plugins', []):
|
||||
for entry in metadata.entry_points().get('inventree_plugins', []): # pragma: no cover
|
||||
try:
|
||||
plugin = entry.load()
|
||||
plugin.is_package = True
|
||||
@ -257,7 +257,7 @@ class PluginsRegistry:
|
||||
except (OperationalError, ProgrammingError) as error:
|
||||
# Exception if the database has not been migrated yet - check if test are running - raise if not
|
||||
if not settings.PLUGIN_TESTING:
|
||||
raise error
|
||||
raise error # pragma: no cover
|
||||
plugin_db_setting = None
|
||||
|
||||
# Always activate if testing
|
||||
@ -267,7 +267,7 @@ class PluginsRegistry:
|
||||
# option1: package, option2: file-based
|
||||
if (plugin.__name__ == disabled) or (plugin.__module__ == disabled):
|
||||
# Errors are bad so disable the plugin in the database
|
||||
if not settings.PLUGIN_TESTING:
|
||||
if not settings.PLUGIN_TESTING: # pragma: no cover
|
||||
plugin_db_setting.active = False
|
||||
# TODO save the error to the plugin
|
||||
plugin_db_setting.save(no_reload=True)
|
||||
@ -445,7 +445,7 @@ class PluginsRegistry:
|
||||
try:
|
||||
app_name = plugin_path.split('.')[-1]
|
||||
app_config = apps.get_app_config(app_name)
|
||||
except LookupError:
|
||||
except LookupError: # pragma: no cover
|
||||
# the plugin was never loaded correctly
|
||||
logger.debug(f'{app_name} App was not found during deregistering')
|
||||
break
|
||||
@ -499,7 +499,7 @@ class PluginsRegistry:
|
||||
# remove model from admin site
|
||||
admin.site.unregister(model)
|
||||
models += [model._meta.model_name]
|
||||
except LookupError:
|
||||
except LookupError: # pragma: no cover
|
||||
# if an error occurs the app was never loaded right -> so nothing to do anymore
|
||||
logger.debug(f'{app_name} App was not found during deregistering')
|
||||
break
|
||||
@ -572,7 +572,7 @@ class PluginsRegistry:
|
||||
try:
|
||||
cmd(*args, **kwargs)
|
||||
return True, []
|
||||
except Exception as error:
|
||||
except Exception as error: # pragma: no cover
|
||||
handle_error(error)
|
||||
# endregion
|
||||
|
||||
|
Reference in New Issue
Block a user