Skip to content

Commit

Permalink
Merge pull request #12844 from rtibbles/plugins_for_the_environment
Browse files Browse the repository at this point in the history
Allow plugins to be enabled, disabled, and applied via env vars.
  • Loading branch information
rtibbles authored Nov 21, 2024
2 parents a75bb2c + 2421e5d commit 849b382
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
51 changes: 50 additions & 1 deletion kolibri/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ def __init__(self):
)
self.save()
logger.info("Initialized plugins.json")
if self.ENV_VAR_APPLIED_PLUGINS:
logger.info(
"Applied plugins from environment variable: {}".format(
self.ENV_VAR_APPLIED_PLUGINS
)
)
if self.ENV_VAR_ENABLED_PLUGINS:
logger.info(
"Enabled plugins from environment variable: {}".format(
self.ENV_VAR_ENABLED_PLUGINS
)
)
if self.ENV_VAR_DISABLED_PLUGINS:
logger.info(
"Disabled plugins from environment variable: {}".format(
self.ENV_VAR_DISABLED_PLUGINS
)
)

def set_defaults(self):
self.update(
Expand All @@ -55,9 +73,40 @@ def set_defaults(self):
}
)

@property
def ENV_VAR_APPLIED_PLUGINS(self):
return [
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_APPLY", "").split(",")
if p.strip()
]

@property
def ENV_VAR_ENABLED_PLUGINS(self):
return set(
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_ENABLE", "").split(",")
if p.strip()
)

@property
def ENV_VAR_DISABLED_PLUGINS(self):
return set(
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_DISABLE", "").split(",")
if p.strip()
)

@property
def ACTIVE_PLUGINS(self):
return list(self["INSTALLED_PLUGINS"] - self["DISABLED_PLUGINS"])
if self.ENV_VAR_APPLIED_PLUGINS:
return self.ENV_VAR_APPLIED_PLUGINS
return list(
(self["INSTALLED_PLUGINS"] - self["DISABLED_PLUGINS"]).union(
self.ENV_VAR_ENABLED_PLUGINS
)
- self.ENV_VAR_DISABLED_PLUGINS
)

def update(self, new_values):
"""
Expand Down
18 changes: 18 additions & 0 deletions kolibri/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ def settings_module():
See the sd_notify(3) man page for more details.
""",
},
"KOLIBRI_PLUGIN_APPLY": {
"description": """
A comma-separated list of plugins to apply. If this variable is set,
only the specified plugins will be applied.
""",
},
"KOLIBRI_PLUGIN_ENABLE": {
"description": """
A comma-separated list of plugins to enable. If this variable is set,
the specified plugins will be enabled, overriding plugins disabled via the CLI.
""",
},
"KOLIBRI_PLUGIN_DISABLE": {
"description": """
A comma-separated list of plugins to disable. If this variable is set,
the specified plugins will be disabled, overriding plugins enabled via the CLI.
""",
},
}


Expand Down

0 comments on commit 849b382

Please sign in to comment.