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: Extension) str[source]
If
file_pathlacks 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_pathhas a JSON-like file extension.- Parameters:
file_path (str) – Any file path
- Returns:
Whether
file_pathhas a JSON-like file extension
- is_yaml_ext(file_path: str, *, strict: bool = False) bool[source]
Returns whether
file_pathhas a YAML-like file extension.
- is_yml_ext(file_path: str, *, strict: bool = False) bool[source]
Returns whether
file_pathhas a YAML-like file extension.
- is_ext(file_path: str, which: Extension, *alts: Extension, strict: bool = False) bool[source]
Returns whether
file_pathhas 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
whichexactly or also allow matching against any extensions inalts
- Returns:
Whether
file_pathhas a file extension from a specific set
- load(config: Any, file_path: str | None = None) Any[source]
Initializes a config object and possibly updates its attributes from file.
Initializes a default config object from
configusingomegaconf. Iffile_pathis 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_pathhas an unsupported file extensionIOError – If there are issues relating to reading from
file_pathOthers – As may be raised by the underlying
omegaconfhandler
- dump(config: Any, file_path: str, *, resolve: bool = False) None[source]
Serializes a config to file.
- Parameters:
config (Any) – Any valid
omegaconfconfig object to serializefile_path (str) – A file path for serializing
configresolve (bool) – Whether the underlying
omegaconfhandler should resolve variable interpolation in the configuration
- Raises:
ValueError – If
file_pathhas an unsupported file extensionIOError – If there are issues relating to writing to
file_pathOthers – As may be raised by the underlying
omegaconfhandler