simplistix / configurator

A Python library for handling configuration files.
https://configurator.readthedocs.io
MIT License
39 stars 6 forks source link

loading a specific "path" of a config file and/or loading multiple of them #8

Closed RonnyPfannschmidt closed 2 years ago

RonnyPfannschmidt commented 2 years ago

i have a setup where we are using dynaconf style environment

which means that instead of

myconfig:
   host: abc
   port: 1337

we have something like

# settings.yaml
default:
  myconfig:
     port: 1337
prod:
  myconfig:
    host: danger.example.com
qe:
  myconfig:
     host: qe.hidden.example.com

then the full config ought to be created via something like

# first rough draft, please destroy :)
def load_config(current_env="qe"):
   setting = Config.from_path("settings.yaml")
   local = Config.from_path("setting.local.yaml", optional=True)
   return merge_from_environments(configs=[settings, local], environments=["global", "default", current_env])
cjw296 commented 2 years ago

Can you provide some pseudocode for merge_from_environments?

RonnyPfannschmidt commented 2 years ago
def merge_from_environments(configs, environments):
   merged = Config()
   for environment in environments:
     for config in configs:
        merged += Config(config.get(environment, {})
   return merged
cjw296 commented 2 years ago

Great to chat yesterday, as discussed, if you can implement this one in your code base (without stuff that can be added when #9 is done!) then we can see about lifting it back into configurator as a pattern once its stable.

Closing this for now, but please comment so we can re-open if you hit problems doing this, or when it's time to bring it upstream.