Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add global filter to disable plugins based on pattern matching #22

Merged
merged 3 commits into from
Jun 4, 2024

Conversation

thrau
Copy link
Member

@thrau thrau commented May 31, 2024

Motivation

Sometimes we want to re-use code that injects plugins we don't want to use. To facilitate this, I added a way to filter plugins based on simple fnmatch rules. You can disable plugins by namespaces, names, or even values.

Here are some examples of how it can be used:

from plux.runtime.filter import global_plugin_filter

# disables all plugins in the `localstack.aws.provider` namespace
global_plugin_filter.add_pattern(namespace = "localstack.aws.provider")

# disables all plugins in namespaces that start with `localstack.aws.`
global_plugin_filter.add_pattern(namespace = "localstack.aws.*")

# disables all plugins that come from the `localstack.services` package, regardless in which namespace
global_plugin_filter.add_pattern(value = "localstack.services.*")

# disables all plugins that come from the `localstack.services` package, but only if they are in the `localstack.aws.provider` namespace
global_plugin_filter.add_pattern(namespace = "localstack.aws.provider", value = "localstack.services.*")

# disables any plugin named "iam-enforcement"
global_plugin_filter.add_pattern(name = "iam-enforcement")

Changes

  • a global filter is added by default to every PluginManager, that does nothing unless configured otherwise

Copy link
Member

@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but a few minor "UX" nits 👍

Great addition allowing more flexibility now when reusing code without having to completely rip out all the existing plugins 🥳

plux/runtime/filter.py Show resolved Hide resolved
plux/runtime/manager.py Show resolved Hide resolved
plux/runtime/filter.py Show resolved Hide resolved
plux/runtime/filter.py Outdated Show resolved Hide resolved
@thrau thrau merged commit 8e8f376 into main Jun 4, 2024
5 checks passed
@thrau thrau deleted the filter-plugins branch June 4, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants