Config#
Parsers#
- class heptools.config.ConfigParser[source]#
A customizable config parser.
- Parameters:
nested (bool, optional, default=True) – Parse dot-separated keys into nested dicts.
tag_parsers (dict[str, Optional[TagParser]], optional) – Custom tags.
extend_methods (dict[str, ExtendMethod], optional) – Custom <extend> methods.
patch_actions (dict[str, PatchAction], optional) – Custom patch actions.
- io#
A config file loader with a shared cache.
- Type:
Protocols#
- heptools.config.ExtendMethod[source]#
A method to merge two values into one.
- Type:
Callable[[Any, Any], Any]
- class heptools.config.TagParser[source]#
Tag parser protocol.
- __call__(*, key, value, tag, tags, local, path)[source]#
- Parameters:
key (str, optional) – The current key.
value (Any, optional) – The current value .
tag (str, optional) – The value of the current tag.
tags (dict[str, Optional[str]], optional) – All parsed tags of the current key.
local (dict, optional) – All parsed items in the current dictionary.
path (str or None, optional) – The path to the current config file.
- Returns:
tuple[str, Any] – The key and value after parsing.
Customization#
- class heptools.config.FileLoader(cache=True)[source]#
A module to load and deserialize objects from URL.
- Parameters:
cache (bool, optional, default=True) – Enable the URL based cache. When an extension is registered or unregistered, the associated cache will be cleared.
- register(handler, *extensions)[source]#
Register a handler for file extensions. This method can be used as a decorator.
- Parameters:
handler (Callable, optional) – Handler function. If not provided, will return a decorator.
*extensions (str) – File extensions to register.