uwtools.api.config
API access to uwtools configuration management tools.
- uwtools.api.config.compare(config_1_path: Union[Path, str], config_2_path: Union[Path, str], config_1_format: Optional[str] = None, config_2_format: Optional[str] = None) bool
Compare two config files.
Recognized file extensions are: ini, nml, sh, yaml
- Parameters
config_1_path – Path to 1st config file
config_2_path – Path to 2nd config file
config_1_format – Format of 1st config file (optional if file’s extension is recognized)
config_2_format – Format of 2nd config file (optional if file’s extension is recognized)
- Returns
Falseif config files had differences, otherwiseTrue
- uwtools.api.config.get_fieldtable_config(config: Optional[Union[dict, str, Path]] = None, stdin_ok=False) FieldTableConfig
Get a
FieldTableConfigobject.- Parameters
config – FieldTable file to load (
Noneor unspecified => readstdin), or initialdictstdin_ok – OK to read from
stdin?
- Returns
An initialized
FieldTableConfigobject
- uwtools.api.config.get_ini_config(config: Optional[Union[dict, str, Path]] = None, stdin_ok: bool = False) INIConfig
Get an
INIConfigobject.- Parameters
config – INI file to load (
Noneor unspecified => readstdin), or initialdictstdin_ok – OK to read from
stdin?
- Returns
An initialized
INIConfigobject
- uwtools.api.config.get_nml_config(config: Optional[Union[dict, str, Path]] = None, stdin_ok: bool = False) NMLConfig
Get an
NMLConfigobject.- Parameters
config – Fortran namelist file to load (
Noneor unspecified => readstdin), or initialdictstdin_ok – OK to read from
stdin?
- Returns
An initialized
NMLConfigobject
- uwtools.api.config.get_sh_config(config: Optional[Union[dict, str, Path]] = None, stdin_ok: bool = False) SHConfig
Get an
SHConfigobject.- Parameters
config – File of shell ‘key=value’ pairs to load (
Noneor unspecified => readstdin), or initialdictstdin_ok – OK to read from
stdin?
- Returns
An initialized
SHConfigobject
- uwtools.api.config.get_yaml_config(config: Optional[Union[dict, str, Path]] = None, stdin_ok: bool = False) YAMLConfig
Get a
YAMLConfigobject.- Parameters
config – YAML file to load (
Noneor unspecified => readstdin), or initialdictstdin_ok – OK to read from
stdin?
- Returns
An initialized
YAMLConfigobject
- uwtools.api.config.realize(input_config: Optional[Union[dict, Config, Path, str]] = None, input_format: Optional[str] = None, update_config: Optional[Union[dict, Config, Path, str]] = None, update_format: Optional[str] = None, output_file: Optional[Union[str, Path]] = None, output_format: Optional[str] = None, key_path: Optional[List[Union[str, int]]] = None, values_needed: bool = False, total: bool = False, dry_run: bool = False, stdin_ok: bool = False) None
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 – Input config file (
Noneor unspecified => readstdin)input_format – Format of the input config (optional if file’s extension is recognized)
update_config – Update config file (
Noneor unspecified => readstdin)update_format – Format of the update config (optional if file’s extension is recognized)
output_file – Output config file (
Noneor unspecified => write tostdout)output_format – Format of the output config (optional if file’s extension is recognized)
key_path – Path through keys to the desired output block
values_needed – Report complete, missing, and template values
total – Require rendering of all Jinja2 variables/expressions
dry_run – Log output instead of writing to output
stdin_ok – OK to read from
stdin?
- Raises
UWConfigRealizeError if
totalisTrueand any Jinja2 variable/expression was not rendered
- uwtools.api.config.realize_to_dict(input_config: Optional[Union[dict, Config, Path, str]] = None, input_format: Optional[str] = None, update_config: Optional[Union[dict, Config, Path, str]] = None, update_format: Optional[str] = None, values_needed: bool = False, dry_run: bool = False, stdin_ok: bool = False) dict
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: Union[Path, str], config: Optional[Union[dict, YAMLConfig, Path, str]] = None, stdin_ok: bool = False) bool
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.- Parameters
schema_file – The JSON Schema file to use for validation
config – The config to validate
stdin_ok – OK to read from
stdin?
- Returns
Trueif the YAML file conforms to the schema,Falseotherwise