coma.config.io
Utilities for serializing configs to file.
- class Extension(value)[source]
Supported config serialization file extensions:
Value
Meaning
YAML
".yaml"
YML
".yml"
JSON
".json"
- maybe_add_ext(file_path: str, ext: coma.config.io.Extension) str [source]
If
file_path
lacks a file extension, appendsext
.- Parameters
file_path (str) – Any file path
ext (coma.config.io.Extension) – An extension to possibly append
- Returns
A file path with an extension if one was lacking
- is_json_ext(file_path: str) bool [source]
Returns whether
file_path
has a JSON-like file extension.- Parameters
file_path (str) – Any file path
- Returns
Whether
file_path
has a JSON-like file extension
- is_yaml_ext(file_path: str, *, strict: bool = False) bool [source]
Returns whether
file_path
has a YAML-like file extension.
- is_yml_ext(file_path: str, *, strict: bool = False) bool [source]
Returns whether
file_path
has a YAML-like file extension.
- is_ext(file_path: str, which: coma.config.io.Extension, *alts: coma.config.io.Extension, strict: bool = False) bool [source]
Returns whether
file_path
has a file extension from a specific set.- Parameters
file_path (str) – Any file path
which (coma.config.io.Extension) – The primary file extension to test against
*alts (coma.config.io.Extension) – A set of alternative file extensions to test against
strict (bool) – Whether to match
which
exactly or also allow matching against any extensions inalts
- Returns
Whether
file_path
has a file extension from a specific set
- load(config: Any, file_path: Optional[str] = None) Any [source]
Initializes a config object and possibly updates its attributes from file.
Initializes a default config object from
config
usingomegaconf
. Iffile_path
is notNone
, attempts to also load a config object from file. If that succeeds, then attempts to update the default config object’s attributes with attributes of the config object loaded from file.- Parameters
- Returns
A new config object, possibly updated from file
- Raises
ValueError – If
file_path
has an unsupported file extensionIOError – If there are issues relating to reading from
file_path
Others – As may be raised by the underlying
omegaconf
handler
- dump(config: Any, file_path: str, *, resolve: bool = False) None [source]
Serializes a config to file.
- Parameters
config (Any) – Any valid
omegaconf
config object to serializefile_path (str) – A file path for serializing
config
resolve (bool) – Whether the underlying
omegaconf
handler should resolve variable interpolation in the configuration
- Raises
ValueError – If
file_path
has an unsupported file extensionIOError – If there are issues relating to writing to
file_path
Others – As may be raised by the underlying
omegaconf
handler