uwtools.api.config
API access to uwtools configuration management tools.
- uwtools.api.config.compare(config_1_path, config_2_path, config_1_format=None, config_2_format=None)
Compare two config files.
Recognized file extensions are: ini, nml, sh, yaml
- uwtools.api.config.get_fieldtable_config(config=None, stdin_ok=False)
Get a
FieldTableConfigobject.
- uwtools.api.config.get_ini_config(config=None, stdin_ok=False)
Get an
INIConfigobject.
- uwtools.api.config.get_nml_config(config=None, stdin_ok=False)
Get an
NMLConfigobject.
- uwtools.api.config.get_sh_config(config=None, stdin_ok=False)
Get an
SHConfigobject.
- uwtools.api.config.get_yaml_config(config=None, stdin_ok=False)
Get a
YAMLConfigobject.
- uwtools.api.config.realize(input_config=None, input_format=None, update_config=None, update_format=None, output_file=None, output_format=None, key_path=None, values_needed=False, total=False, dry_run=False, stdin_ok=False)
Realize a config based on a base input config and an optional update config.
The input config may be specified as a filesystem path, a
dict, or aConfigobject. When it is not, it will be read fromstdin.If an update config is specified, it is merged onto the input config, augmenting or overriding base values. It may be specified as a filesystem path, a
dict, or aConfigobject. When it is not, it will be read fromstdin.At most one of the input config or the update config may be left unspecified, in which case the other will be read from
stdin. If neither filename or format is specified for the update config, no update will be performed.The output destination may be specified as a filesystem path. When it is not, it will be written to
stdout.If
values_neededisTrue, a report of values needed to realize the config is logged. Indry_runmode, output is written tostderr.If
totalisTrue, an exception will be raised if any Jinja2 variables/expressions cannot be rendered. Otherwise, such variables/expressions will be passed through unchanged in the output.Recognized file extensions are: ini, nml, sh, yaml
- Parameters:
input_config (Config | Path | dict | str | None) – Input config file (
None=> readstdin).input_format (str | None) – Format of the input config (optional if file’s extension is recognized).
update_config (Config | Path | dict | str | None) – Update config file (
None=> readstdin).update_format (str | None) – Format of the update config (optional if file’s extension is recognized).
output_file (str | Path | None) – Output config file (
None=> write tostdout).output_format (str | None) – Format of the output config (optional if file’s extension is recognized).
key_path (list[str | int] | None) – Path through keys to the desired output block.
values_needed (bool) – Report complete, missing, and template values.
total (bool) – Require rendering of all Jinja2 variables/expressions.
dry_run (bool) – Log output instead of writing to output.
stdin_ok (bool) – OK to read from
stdin?
- Returns:
The
dictrepresentation of the realized config.- Raises:
UWConfigRealizeError if
totalisTrueand any Jinja2 variable/expression was not rendered.- Return type:
- uwtools.api.config.realize_to_dict(input_config=None, input_format=None, update_config=None, update_format=None, key_path=None, values_needed=False, total=False, dry_run=False, stdin_ok=False)
Realize a config to a
dict, based on a base input config and an optional update config.See
realize()for details on arguments, etc.
- uwtools.api.config.validate(schema_file, config=None, stdin_ok=False)
Check whether the specified config conforms to the specified JSON Schema spec.
If no config is specified,
stdinis read and will be parsed as YAML and then validated. Adictor a YAMLConfig instance may also be provided for validation.