Skip to content

Instantly share code, notes, and snippets.

@timhoffm
Last active December 6, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhoffm/0a4d3d2b01115d77f930ceaadc4523ac to your computer and use it in GitHub Desktop.
Save timhoffm/0a4d3d2b01115d77f930ceaadc4523ac to your computer and use it in GitHub Desktop.
Config system

Requirements

  • access config['axes.xticks.color'] and config.axes.xticks.color. Which one is the preferred? Or both?
  • validators
  • default values? resetting?
  • virtual or real hierarchy: Is the structure only naming convention or do we want to define explicit structure components?
  • support aliases, possibility for deprecated aliases
  • simple layering of configs (ChainMap-like?)
  • Definition of values should be explicit (e.g. ArgumentParser-style)
    config.add_param('lines.width', type=float, description="The width of all lines in points")
  • option for inferred values ("grid.linewidth" should use the value from "lines.width")
  • fast access - may be needed often in constructors for 'small' objects like ticks.
  • contexts

To clarify

How do other libraries handle this? numpy, scipy, scikit image, pandas,

validators:

  • types: assert isinstance(x, type)
  • lists: assert x in list
  • callable: assert func(x)
  • preprocessor x = func(x)

Context API variants

with config({'axes.xticks.color': 'red', 'axes.xticks.edgewidth': 4}):

with config({'axes.xticks': {'color': 'red', 'edgewidth': 4}}):

with config(axes_xticks_color='red', axes_xticks_edgewidth=4}):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment