localstack / plux

A dynamic code loading framework for building pluggable Python distributions
https://github.com/localstack/plux
Apache License 2.0
72 stars 0 forks source link

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

Closed thrau closed 5 months ago

thrau commented 5 months ago

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