mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-30 18:50:53 +00:00
Docstring checks in QC checks (#3089)
* Add pre-commit to the stack * exclude static * Add locales to excludes * fix style errors * rename pipeline steps * also wait on precommit * make template matching simpler * Use the same code for python setup everywhere * use step and cache for python setup * move regular settings up into general envs * just use full update * Use invoke instead of static references * make setup actions more similar * use python3 * refactor names to be similar * fix runner version * fix references * remove incidential change * use matrix for os * Github can't do this right now * ignore docstyle errors * Add seperate docstring test * update flake call * do not fail on docstring * refactor setup into workflow * update reference * switch to action * resturcture * add bash statements * remove os from cache * update input checks * make code cleaner * fix boolean * no relative paths * install wheel by python * switch to install * revert back to simple wheel * refactor import export tests * move setup keys back to not disturbe tests * remove docstyle till that is fixed * update references * continue on error * add docstring test * use relativ action references * Change step / job docstrings * update to merge * reformat comments 1 * fix docstrings 2 * fix docstrings 3 * fix docstrings 4 * fix docstrings 5 * fix docstrings 6 * fix docstrings 7 * fix docstrings 8 * fix docstirns 9 * fix docstrings 10 * docstring adjustments * update the remaining docstrings * small docstring changes * fix function name * update support files for docstrings * Add missing args to docstrings * Remove outdated function * Add docstrings for the 'build' app * Make API code cleaner * add more docstrings for plugin app * Remove dead code for plugin settings No idea what that was even intended for * ignore __init__ files for docstrings * More docstrings * Update docstrings for the 'part' directory * Fixes for related_part functionality * Fix removed stuff from merge99676ee
* make more consistent * Show statistics for docstrings * add more docstrings * move specific register statements to make them clearer to understant * More docstrings for common * and more docstrings * and more * simpler call * docstrings for notifications * docstrings for common/tests * Add docs for common/models * Revert "move specific register statements to make them clearer to understant" This reverts commitca96654622
. * use typing here * Revert "Make API code cleaner" This reverts commit24fb68bd3e
. * docstring updates for the 'users' app * Add generic Meta info to simple Meta classes * remove unneeded unique_together statements * More simple metas * Remove unnecessary format specifier * Remove extra json format specifiers * Add docstrings for the 'plugin' app * Docstrings for the 'label' app * Add missing docstrings for the 'report' app * Fix build test regression * Fix top-level files * docstrings for InvenTree/InvenTree * reduce unneeded code * add docstrings * and more docstrings * more docstrings * more docstrings for stock * more docstrings * docstrings for order/views * Docstrings for various files in the 'order' app * Docstrings for order/test_api.py * Docstrings for order/serializers.py * Docstrings for order/admin.py * More docstrings for the order app * Add docstrings for the 'company' app * Add unit tests for rebuilding the reference fields * Prune out some more dead code * remove more dead code Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com>
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
"""
|
||||
Registry for loading and managing multiple plugins at run-time
|
||||
"""Registry for loading and managing multiple plugins at run-time.
|
||||
|
||||
- Holds the class and the object that contains all code to maintain plugin states
|
||||
- Manages setup and teardown of plugin class instances
|
||||
@ -31,11 +30,13 @@ logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class PluginsRegistry:
|
||||
"""
|
||||
The PluginsRegistry class
|
||||
"""
|
||||
"""The PluginsRegistry class."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize registry.
|
||||
|
||||
Set up all needed references for internal and external states.
|
||||
"""
|
||||
# plugin registry
|
||||
self.plugins = {}
|
||||
self.plugins_inactive = {}
|
||||
@ -55,10 +56,7 @@ class PluginsRegistry:
|
||||
self.mixins_settings = {}
|
||||
|
||||
def get_plugin(self, slug):
|
||||
"""
|
||||
Lookup plugin by slug (unique key).
|
||||
"""
|
||||
|
||||
"""Lookup plugin by slug (unique key)."""
|
||||
if slug not in self.plugins:
|
||||
logger.warning(f"Plugin registry has no record of plugin '{slug}'")
|
||||
return None
|
||||
@ -66,15 +64,13 @@ class PluginsRegistry:
|
||||
return self.plugins[slug]
|
||||
|
||||
def call_plugin_function(self, slug, func, *args, **kwargs):
|
||||
"""
|
||||
Call a member function (named by 'func') of the plugin named by 'slug'.
|
||||
"""Call a member function (named by 'func') of the plugin named by 'slug'.
|
||||
|
||||
As this is intended to be run by the background worker,
|
||||
we do not perform any try/except here.
|
||||
|
||||
Instead, any error messages are returned to the worker.
|
||||
"""
|
||||
|
||||
plugin = self.get_plugin(slug)
|
||||
|
||||
if not plugin:
|
||||
@ -87,7 +83,7 @@ class PluginsRegistry:
|
||||
# region public functions
|
||||
# region loading / unloading
|
||||
def load_plugins(self, full_reload: bool = False):
|
||||
"""Load and activate all IntegrationPlugins
|
||||
"""Load and activate all IntegrationPlugins.
|
||||
|
||||
Args:
|
||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||
@ -150,10 +146,7 @@ class PluginsRegistry:
|
||||
logger.info('Finished loading plugins')
|
||||
|
||||
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
|
||||
@ -177,12 +170,11 @@ class PluginsRegistry:
|
||||
logger.info('Finished unloading plugins')
|
||||
|
||||
def reload_plugins(self, full_reload: bool = False):
|
||||
"""Safely reload IntegrationPlugins
|
||||
"""Safely reload.
|
||||
|
||||
Args:
|
||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||
"""
|
||||
|
||||
# Do not reload whe currently loading
|
||||
if self.is_loading:
|
||||
return # pragma: no cover
|
||||
@ -196,8 +188,7 @@ class PluginsRegistry:
|
||||
logger.info('Finished reloading plugins')
|
||||
|
||||
def collect_plugins(self):
|
||||
"""Collect plugins from all possible ways of loading"""
|
||||
|
||||
"""Collect plugins from all possible ways of loading."""
|
||||
if not settings.PLUGINS_ENABLED:
|
||||
# Plugins not enabled, do nothing
|
||||
return # pragma: no cover
|
||||
@ -226,10 +217,7 @@ class PluginsRegistry:
|
||||
logger.info(", ".join([a.__module__ for a in self.plugin_modules]))
|
||||
|
||||
def install_plugin_file(self):
|
||||
"""
|
||||
Make sure all plugins are installed in the current enviroment
|
||||
"""
|
||||
|
||||
"""Make sure all plugins are installed in the current enviroment."""
|
||||
if settings.PLUGIN_FILE_CHECKED:
|
||||
logger.info('Plugin file was already checked')
|
||||
return True
|
||||
@ -250,9 +238,7 @@ class PluginsRegistry:
|
||||
|
||||
# region registry functions
|
||||
def with_mixin(self, mixin: str, active=None):
|
||||
"""
|
||||
Returns reference to all plugins that have a specified mixin enabled
|
||||
"""
|
||||
"""Returns reference to all plugins that have a specified mixin enabled."""
|
||||
result = []
|
||||
|
||||
for plugin in self.plugins.values():
|
||||
@ -273,14 +259,12 @@ class PluginsRegistry:
|
||||
|
||||
# region general internal loading /activating / deactivating / deloading
|
||||
def _init_plugins(self, disabled=None):
|
||||
"""
|
||||
Initialise all found plugins
|
||||
"""Initialise all found plugins.
|
||||
|
||||
:param disabled: loading path of disabled app, defaults to None
|
||||
:type disabled: str, optional
|
||||
:raises error: IntegrationPluginError
|
||||
"""
|
||||
|
||||
from plugin.models import PluginConfig
|
||||
|
||||
logger.info('Starting plugin initialisation')
|
||||
@ -344,7 +328,7 @@ class PluginsRegistry:
|
||||
self.plugins_inactive[plug_key] = plugin_db_setting # pragma: no cover
|
||||
|
||||
def _activate_plugins(self, force_reload=False, full_reload: bool = False):
|
||||
"""Run activation functions for all plugins
|
||||
"""Run activation functions for all plugins.
|
||||
|
||||
Args:
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
@ -359,8 +343,7 @@ class PluginsRegistry:
|
||||
self.activate_plugin_app(plugins, force_reload=force_reload, full_reload=full_reload)
|
||||
|
||||
def _deactivate_plugins(self):
|
||||
"""Run deactivation functions for all plugins"""
|
||||
|
||||
"""Run deactivation functions for all plugins."""
|
||||
self.deactivate_plugin_app()
|
||||
self.deactivate_plugin_schedule()
|
||||
self.deactivate_plugin_settings()
|
||||
@ -368,7 +351,11 @@ class PluginsRegistry:
|
||||
|
||||
# region mixin specific loading ...
|
||||
def activate_plugin_settings(self, plugins):
|
||||
"""Activate plugin settings.
|
||||
|
||||
Add all defined settings form the plugins to a unified dict in the registry.
|
||||
This dict is referenced by the PluginSettings for settings definitions.
|
||||
"""
|
||||
logger.info('Activating plugin settings')
|
||||
|
||||
self.mixins_settings = {}
|
||||
@ -379,18 +366,13 @@ class PluginsRegistry:
|
||||
self.mixins_settings[slug] = plugin_setting
|
||||
|
||||
def deactivate_plugin_settings(self):
|
||||
|
||||
# collect all settings
|
||||
plugin_settings = {}
|
||||
|
||||
for _, plugin_setting in self.mixins_settings.items():
|
||||
plugin_settings.update(plugin_setting)
|
||||
|
||||
# clear cache
|
||||
"""Deactivate all plugin settings."""
|
||||
logger.info('Deactivating plugin settings')
|
||||
# clear settings cache
|
||||
self.mixins_settings = {}
|
||||
|
||||
def activate_plugin_schedule(self, plugins):
|
||||
|
||||
"""Activate scheudles from plugins with the ScheduleMixin."""
|
||||
logger.info('Activating plugin tasks')
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
@ -434,21 +416,20 @@ class PluginsRegistry:
|
||||
logger.warning("activate_integration_schedule failed, database not ready")
|
||||
|
||||
def deactivate_plugin_schedule(self):
|
||||
"""
|
||||
Deactivate ScheduleMixin
|
||||
currently nothing is done
|
||||
"""Deactivate ScheduleMixin.
|
||||
|
||||
Currently nothing is done here.
|
||||
"""
|
||||
pass
|
||||
|
||||
def activate_plugin_app(self, plugins, force_reload=False, full_reload: bool = False):
|
||||
"""Activate AppMixin plugins - add custom apps and reload
|
||||
"""Activate AppMixin plugins - add custom apps and reload.
|
||||
|
||||
Args:
|
||||
plugins (dict): List of IntegrationPlugins that should be installed
|
||||
force_reload (bool, optional): Only reload base apps. Defaults to False.
|
||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||
"""
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_APP'):
|
||||
@ -480,9 +461,10 @@ class PluginsRegistry:
|
||||
self._update_urls()
|
||||
|
||||
def _reregister_contrib_apps(self):
|
||||
"""fix reloading of contrib apps - models and admin
|
||||
this is needed if plugins were loaded earlier and then reloaded as models and admins rely on imports
|
||||
those register models and admin in their respective objects (e.g. admin.site for admin)
|
||||
"""Fix reloading of contrib apps - models and admin.
|
||||
|
||||
This is needed if plugins were loaded earlier and then reloaded as models and admins rely on imports.
|
||||
Those register models and admin in their respective objects (e.g. admin.site for admin).
|
||||
"""
|
||||
for plugin_path in self.installed_apps:
|
||||
try:
|
||||
@ -512,8 +494,9 @@ class PluginsRegistry:
|
||||
reload(app_config.module.admin)
|
||||
|
||||
def _get_plugin_path(self, plugin):
|
||||
"""parse plugin path
|
||||
the input can be eiter:
|
||||
"""Parse plugin path.
|
||||
|
||||
The input can be eiter:
|
||||
- a local file / dir
|
||||
- a package
|
||||
"""
|
||||
@ -526,8 +509,7 @@ class PluginsRegistry:
|
||||
return plugin_path
|
||||
|
||||
def deactivate_plugin_app(self):
|
||||
"""Deactivate AppMixin plugins - some magic required"""
|
||||
|
||||
"""Deactivate AppMixin plugins - some magic required."""
|
||||
# unregister models from admin
|
||||
for plugin_path in self.installed_apps:
|
||||
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed
|
||||
@ -598,13 +580,12 @@ class PluginsRegistry:
|
||||
clear_url_caches()
|
||||
|
||||
def _reload_apps(self, force_reload: bool = False, full_reload: bool = False):
|
||||
"""Internal: reload apps using django internal functions
|
||||
"""Internal: reload apps using django internal functions.
|
||||
|
||||
Args:
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||
"""
|
||||
|
||||
# If full_reloading is set to true we do not want to set the flag
|
||||
if not full_reload:
|
||||
self.is_loading = True # set flag to disable loop reloading
|
||||
@ -619,9 +600,9 @@ class PluginsRegistry:
|
||||
self.is_loading = False
|
||||
|
||||
def _try_reload(self, cmd, *args, **kwargs):
|
||||
"""
|
||||
wrapper to try reloading the apps
|
||||
throws an custom error that gets handled by the loading function
|
||||
"""Wrapper to try reloading the apps.
|
||||
|
||||
Throws an custom error that gets handled by the loading function.
|
||||
"""
|
||||
try:
|
||||
cmd(*args, **kwargs)
|
||||
@ -635,5 +616,5 @@ registry = PluginsRegistry()
|
||||
|
||||
|
||||
def call_function(plugin_name, function_name, *args, **kwargs):
|
||||
""" Global helper function to call a specific member function of a plugin """
|
||||
"""Global helper function to call a specific member function of a plugin."""
|
||||
return registry.call_plugin_function(plugin_name, function_name, *args, **kwargs)
|
||||
|
Reference in New Issue
Block a user