Replies: 1 comment
-
There is no feature (yet) that covers this merging strategy, The option to reach the desired behavior is to create a custom loader that will take care of loading your plugin data. Create a plugin_loader.py in your application # myproject/plugin_loader.py
from dynaconf.base import SourceMetadata
def load(obj, env=None, silent=True, key=None, filename=None):
"""loads files listed on obj.PLUGIN_SETTINGS_FILES
obj = the settings instance
"""
for filename in obj.get("PLUGIN_SETTINGS_FILES", []):
found_file = obj.find_file(filename)
if not found_file:
continue
with open(found_file) as settings_file:
# IMPLEMENT YOUR LOGIC HERE
# parse the file data
# traverse the data checking if is already set on `obj`
# build a dictionary with the data to be merged omiting the
# existing data to avoid override.
data = {"dynaconf_merge": True}
# UPDATE THE SETTINGS WITH DATA
source_metadata = SourceMetadata("plugin", found_file, "default")
obj.update(data, loader_identifier=source_metadata) Then on your dynaconf instance register the custom loader settings = Dynaconf(
...
PLUGIN_SETTINGS_FILES=["plugin1.yaml", "plugin2.yaml"], # or load it dynamically
LOADERS_FOR_DYNACONF=["myproject.plugin_loader", "dynaconf.loaders.env_loader"]
) I wish we had a better API for doing that, but we don't have it yet. ProposalsIn the future, we can try to implement: Easier way to register nwe loaders@settings.loader
def load_plugin_data(....):
.... Different merging strategies #299settings = Dynaconf(
merge_strategy=OnlyMissing
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an application calling plugins which are potentially loaded during runtime and come with their own (default) settings. I want to apply settings that are defined somewhere in the application's dynaconf settings and complete these with default values the plugin defines in case of settings which have not yet been set in the application's dynaconf setting object. Basically a merge without override. What is the preferred way to accomplish this in dynaconf?
Beta Was this translation helpful? Give feedback.
All reactions