marsh.config

Tools for reading and writing config files.

Support for new file extensions may be added by registering more config schemas.

meta_key: str = '_meta_'

This key is used to store any metadata in a config.

The metadata is typically dropped after variable interpolations have been performed.

tree(path)[source]

Get a tree representation of a directory recursively searched for configs.

Parameters:

path (str) – The path to a directory.

Return type:

str

Returns:

A tree representation of all available configs in that directory.

load(name, *names, root=None, resolve=True, keep_meta=False, concatenate=False)[source]

Load one or more config files.

When more than one config is loaded their contents are merged and the values of the succeeding config takes priority for fields where a merge can not be performed.

File extensions may be omitted.

Parameters:
  • name (str) – Name of a config file.

  • *names (str) – Any additional config files.

  • root (Optional[str]) – A root working directory for the config files. Defaults to the current working directory.

  • resolve (bool) – Resolve omegaconf interpolations.

  • keep_meta (bool) – Keep meta field if it exists.

  • concatenate (bool) – Concatenate sequences when multiple configs are loaded and merged instead of replacing the previous value.

Return type:

Union[None, int, float, bool, str, Sequence[Any], Mapping[str, Any]]

Returns:

The loaded config.

write(config, path='-')[source]

Write a config to a file.

By default the config is written to stdout in YAML format.

Parameters:
Return type:

None

drop_meta(config)[source]

Drop the meta key with all its values if present.

Parameters:

config (Union[None, int, float, bool, str, Sequence[Any], Mapping[str, Any]]) – Config to drop meta data from.

Return type:

Union[None, int, float, bool, str, Sequence[Any], Mapping[str, Any]]

Returns:

Input config without meta data.