simplistix / configurator

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

case insensitive loading/lookup as opt-in #10

Open RonnyPfannschmidt opened 2 years ago

RonnyPfannschmidt commented 2 years ago

when migrating from other configuration systems, those sometimes are very lenient on how they deal with uppercase/lowercase/mixed case keys

it would be nice to be able to

  1. normalize the case of keys on loading + warning when normalization was necessary
  2. normalize the case of lookup when using config objects in old code

example:

# settings.yaml
MAIN:
  hostname: deathstar.example.com
# load_config.py

config = Config.from_path("settings.yaml")
fixed_config = Config()
fixed_config.merge(config, context=CaseNormalizer(normalize=str.lower, warn=True)
# warns here about MAIN needing to be renamed to main

safely_usable_config = CaseSensitiveLookup(fixed_config)
def get_host(settings):
   # legacy code, gets warning about MAIN and HOST
   return settings.MAIN.HOST

get_host(safely_usable_config)