Skip to content

Commit

Permalink
feat: Extend plugin configuration loader to support dynamic levels
Browse files Browse the repository at this point in the history
Previously, the configuration loader in `BasePlugin` only supported loading plugin configurations from the `plugins` section of the `config.yaml` file. This approach limited flexibility and made it incompatible with new configuration structures.

With this update, the configuration loader now supports additional sections, such as `community-plugins` and `custom-plugins`, while maintaining backward compatibility. Plugins can access their configurations regardless of where they are defined in the file.

- Added dynamic search across multiple levels: `plugins`, `community-plugins`, and `custom-plugins`.
- Ensured `plugins` is prioritized to avoid breaking existing setups.
- Plugins retain access to their full configuration through `self.config`.

How to access configuration in plugins:
- Use `self.config` to retrieve plugin-specific options.
- Example: `self.config.get('active', False)` checks if the plugin is active.
- All configuration options from the corresponding section (e.g., `plugins`, `community-plugins`) are available dynamically.
  • Loading branch information
fernandodpr committed Nov 27, 2024
1 parent 8d98d42 commit 025d688
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugins/base_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def __init__(self) -> None:
super().__init__()
self.logger = get_logger(f"Plugin:{self.plugin_name}")
self.config = {"active": False}
if "plugins" in relay_config and self.plugin_name in relay_config["plugins"]:
self.config = relay_config["plugins"][self.plugin_name]
plugin_levels = ["plugins", "community-plugins", "custom-plugins"]

for level in plugin_levels:
if level in relay_config and self.plugin_name in relay_config[level]:
self.config = relay_config[level][self.plugin_name]
break

def start(self):
if "schedule" not in self.config or (
Expand Down

0 comments on commit 025d688

Please sign in to comment.