mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
update the remaining docstrings
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
"""Base Class for InvenTree plugins"""
|
||||
"""Base Class for InvenTree plugins."""
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
@ -19,7 +19,7 @@ logger = logging.getLogger("inventree")
|
||||
|
||||
|
||||
class MetaBase:
|
||||
"""Base class for a plugins metadata"""
|
||||
"""Base class for a plugins metadata."""
|
||||
|
||||
# Override the plugin name for each concrete plugin instance
|
||||
NAME = ''
|
||||
@ -27,7 +27,7 @@ class MetaBase:
|
||||
TITLE = None
|
||||
|
||||
def get_meta_value(self, key: str, old_key: str = None, __default=None):
|
||||
"""Reference a meta item with a key
|
||||
"""Reference a meta item with a key.
|
||||
|
||||
Args:
|
||||
key (str): key for the value
|
||||
@ -53,16 +53,16 @@ class MetaBase:
|
||||
return value
|
||||
|
||||
def plugin_name(self):
|
||||
"""Name of plugin"""
|
||||
"""Name of plugin."""
|
||||
return self.get_meta_value('NAME', 'PLUGIN_NAME')
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Name of plugin"""
|
||||
"""Name of plugin."""
|
||||
return self.plugin_name()
|
||||
|
||||
def plugin_slug(self):
|
||||
"""Slug of plugin
|
||||
"""Slug of plugin.
|
||||
|
||||
If not set plugin name slugified
|
||||
"""
|
||||
@ -74,11 +74,11 @@ class MetaBase:
|
||||
|
||||
@property
|
||||
def slug(self):
|
||||
"""Slug of plugin"""
|
||||
"""Slug of plugin."""
|
||||
return self.plugin_slug()
|
||||
|
||||
def plugin_title(self):
|
||||
"""Title of plugin"""
|
||||
"""Title of plugin."""
|
||||
title = self.get_meta_value('TITLE', 'PLUGIN_TITLE', None)
|
||||
if title:
|
||||
return title
|
||||
@ -86,11 +86,11 @@ class MetaBase:
|
||||
|
||||
@property
|
||||
def human_name(self):
|
||||
"""Human readable name of plugin"""
|
||||
"""Human readable name of plugin."""
|
||||
return self.plugin_title()
|
||||
|
||||
def plugin_config(self):
|
||||
"""Return the PluginConfig object associated with this plugin"""
|
||||
"""Return the PluginConfig object associated with this plugin."""
|
||||
try:
|
||||
import plugin.models
|
||||
|
||||
@ -104,7 +104,7 @@ class MetaBase:
|
||||
return cfg
|
||||
|
||||
def is_active(self):
|
||||
"""Return True if this plugin is currently active"""
|
||||
"""Return True if this plugin is currently active."""
|
||||
cfg = self.plugin_config()
|
||||
|
||||
if cfg:
|
||||
@ -114,7 +114,7 @@ class MetaBase:
|
||||
|
||||
|
||||
class MixinBase:
|
||||
"""Base set of mixin functions and mechanisms"""
|
||||
"""Base set of mixin functions and mechanisms."""
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
self._mixinreg = {}
|
||||
@ -122,11 +122,11 @@ class MixinBase:
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def mixin(self, key):
|
||||
"""Check if mixin is registered"""
|
||||
"""Check if mixin is registered."""
|
||||
return key in self._mixins
|
||||
|
||||
def mixin_enabled(self, key):
|
||||
"""Check if mixin is registered, enabled and ready"""
|
||||
"""Check if mixin is registered, enabled and ready."""
|
||||
if self.mixin(key):
|
||||
fnc_name = self._mixins.get(key)
|
||||
|
||||
@ -138,12 +138,12 @@ class MixinBase:
|
||||
return False
|
||||
|
||||
def add_mixin(self, key: str, fnc_enabled=True, cls=None):
|
||||
"""Add a mixin to the plugins registry"""
|
||||
"""Add a mixin to the plugins registry."""
|
||||
self._mixins[key] = fnc_enabled
|
||||
self.setup_mixin(key, cls=cls)
|
||||
|
||||
def setup_mixin(self, key, cls=None):
|
||||
"""Define mixin details for the current mixin -> provides meta details for all active mixins"""
|
||||
"""Define mixin details for the current mixin -> provides meta details for all active mixins."""
|
||||
# get human name
|
||||
human_name = getattr(cls.MixinMeta, 'MIXIN_NAME', key) if cls and hasattr(cls, 'MixinMeta') else key
|
||||
|
||||
@ -155,7 +155,7 @@ class MixinBase:
|
||||
|
||||
@property
|
||||
def registered_mixins(self, with_base: bool = False):
|
||||
"""Get all registered mixins for the plugin"""
|
||||
"""Get all registered mixins for the plugin."""
|
||||
mixins = getattr(self, '_mixinreg', None)
|
||||
if mixins:
|
||||
# filter out base
|
||||
@ -167,7 +167,7 @@ class MixinBase:
|
||||
|
||||
|
||||
class InvenTreePlugin(MixinBase, MetaBase):
|
||||
"""The InvenTreePlugin class is used to integrate with 3rd party software
|
||||
"""The InvenTreePlugin class is used to integrate with 3rd party software.
|
||||
|
||||
DO NOT USE THIS DIRECTLY, USE plugin.InvenTreePlugin
|
||||
"""
|
||||
@ -190,7 +190,7 @@ class InvenTreePlugin(MixinBase, MetaBase):
|
||||
# region properties
|
||||
@property
|
||||
def description(self):
|
||||
"""Description of plugin"""
|
||||
"""Description of plugin."""
|
||||
description = getattr(self, 'DESCRIPTION', None)
|
||||
if not description:
|
||||
description = self.plugin_name()
|
||||
@ -220,7 +220,7 @@ class InvenTreePlugin(MixinBase, MetaBase):
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""Version of plugin"""
|
||||
"""Version of plugin."""
|
||||
version = getattr(self, 'VERSION', None)
|
||||
return version
|
||||
|
||||
@ -232,14 +232,14 @@ class InvenTreePlugin(MixinBase, MetaBase):
|
||||
|
||||
@property
|
||||
def license(self):
|
||||
"""License of plugin"""
|
||||
"""License of plugin."""
|
||||
lic = getattr(self, 'LICENSE', None)
|
||||
return lic
|
||||
# endregion
|
||||
|
||||
@property
|
||||
def _is_package(self):
|
||||
"""Is the plugin delivered as a package"""
|
||||
"""Is the plugin delivered as a package."""
|
||||
return getattr(self, 'is_package', False)
|
||||
|
||||
@property
|
||||
@ -250,27 +250,27 @@ class InvenTreePlugin(MixinBase, MetaBase):
|
||||
|
||||
@property
|
||||
def package_path(self):
|
||||
"""Path to the plugin"""
|
||||
"""Path to the plugin."""
|
||||
if self._is_package:
|
||||
return self.__module__ # pragma: no cover
|
||||
return pathlib.Path(self.def_path).relative_to(settings.BASE_DIR)
|
||||
|
||||
@property
|
||||
def settings_url(self):
|
||||
"""URL to the settings panel for this plugin"""
|
||||
"""URL to the settings panel for this plugin."""
|
||||
return f'{reverse("settings")}#select-plugin-{self.slug}'
|
||||
|
||||
# region package info
|
||||
def _get_package_commit(self):
|
||||
"""Get last git commit for the plugin"""
|
||||
"""Get last git commit for the plugin."""
|
||||
return get_git_log(self.def_path)
|
||||
|
||||
def _get_package_metadata(self):
|
||||
"""Get package metadata for plugin"""
|
||||
"""Get package metadata for plugin."""
|
||||
return {} # pragma: no cover # TODO add usage for package metadata
|
||||
|
||||
def define_package(self):
|
||||
"""Add package info of the plugin into plugins context"""
|
||||
"""Add package info of the plugin into plugins context."""
|
||||
package = self._get_package_metadata() if self._is_package else self._get_package_commit()
|
||||
|
||||
# process date
|
||||
@ -294,7 +294,7 @@ class InvenTreePlugin(MixinBase, MetaBase):
|
||||
|
||||
class IntegrationPluginBase(InvenTreePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Send warning about using this reference"""
|
||||
"""Send warning about using this reference."""
|
||||
# TODO remove in 0.8.0
|
||||
warnings.warn("This import is deprecated - use InvenTreePlugin", DeprecationWarning)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
Reference in New Issue
Block a user