Skip to content

Commit

Permalink
Add warnings when trying to modify plugins after registry is loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Dec 18, 2021
1 parent a76bb72 commit e68b9b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kolibri/plugins/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
logger = logging.getLogger(__name__)


__initialized = False


class PluginExistsInApp(Exception):
"""
This exception is raise when a plugin is initialized inside a Django app and
Expand Down Expand Up @@ -163,6 +166,7 @@ def __initialize():
"""
Called once to register hook callbacks.
"""
global __initialized
registry = Registry()
logger.debug("Loading kolibri plugin registry...")
was_configured = settings.configured
Expand All @@ -171,7 +175,12 @@ def __initialize():
"Django settings already configured when plugin registry initialized"
)
registry.register_plugins(config.ACTIVE_PLUGINS)
__initialized = True
return registry


registered_plugins = SimpleLazyObject(__initialize)


def is_initialized():
return __initialized
10 changes: 10 additions & 0 deletions kolibri/plugins/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def autoremove_unavailable_plugins():
configured by the user or some other kind of hard dependency that should
make execution stop if not loadable.
"""
from kolibri.plugins.registry import is_initialized

if is_initialized():
# TODO: Turn this into a Runtime error
logger.warning("Attempted to updated plugins when registry is initialized")
changed = False
# Iterate over a copy of the set so that it is not modified during the loop
for module_path in config["INSTALLED_PLUGINS"].copy():
Expand All @@ -415,6 +420,11 @@ def enable_new_default_plugins():
default plugins that have been explicitly disabled by a user,
in versions prior to the implementation of a plugin blacklist.
"""
from kolibri.plugins.registry import is_initialized

if is_initialized():
# TODO: Turn this into a Runtime error
logger.warning("Attempted to updated plugins when registry is initialized")
changed = False
for module_path in DEFAULT_PLUGINS:
if module_path not in config["INSTALLED_PLUGINS"]:
Expand Down

0 comments on commit e68b9b6

Please sign in to comment.