uwtools.api.config
- 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, Path, str]] = None) FieldTableConfig
Get a
FieldTableConfigobject.- Parameters
config – FieldTable file to load (
Noneor unspecified => readstdin), or initialdict- Returns
An initialized
FieldTableConfigobject
- uwtools.api.config.get_ini_config(config: Optional[Union[dict, Path, str]] = None) INIConfig
Get an
INIConfigobject.- Parameters
config – INI file to load (
Noneor unspecified => readstdin), or initialdict- Returns
An initialized
INIConfigobject
- uwtools.api.config.get_nml_config(config: Optional[Union[dict, Path, str]] = None) NMLConfig
Get an
NMLConfigobject.- Parameters
config – Fortran namelist file to load (
Noneor unspecified => readstdin), or initialdict- Returns
An initialized
NMLConfigobject
- uwtools.api.config.get_sh_config(config: Optional[Union[dict, Path, str]] = None) SHConfig
Get an
SHConfigobject.- Parameters
config – File of shell ‘key=value’ pairs to load (
Noneor unspecified => readstdin), or initialdict- Returns
An initialized
SHConfigobject
- uwtools.api.config.get_yaml_config(config: Optional[Union[dict, Path, str]] = None) YAMLConfig
Get a
YAMLConfigobject.- Parameters
config – YAML file to load (
Noneor unspecified => readstdin), or initialdict- Returns
An initialized
YAMLConfigobject
- uwtools.api.config.realize(input_config: Optional[Union[dict, Config, Path, str]] = None, input_format: Optional[str] = None, output_file: Optional[Union[Path, str]] = None, output_format: Optional[str] = None, supplemental_configs: Optional[List[Union[dict, Config, Path, str]]] = None, values_needed: bool = False, dry_run: bool = False) bool
Realize an output config based on an input config and optional supplemental configs.
If no input is specified,
stdinis read. AdictorConfigobject may also be provided as input. If no output is specified,stdoutis written to. When an input or output filename is specified, its format will be deduced from its extension, if possible. This can be overridden by specifying the format explicitly, and it is required to do so for reads fromstdinor writes tostdout, as no attempt is made to deduce the format of streamed data.If optional supplemental configs (which may likewise be file paths or
Config/dictobjects) are provided, they will be merged, in the order specified, onto the input config. The format of all input configs must match.If the input-config format is YAML, any supported output format may be specified. For all other input formats, the output format must match the input.
If
values_neededisTrue, a report of values needed to realize the config is logged. Indry_runmode, output is written tostderr.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)
output_file – Output config file (
Noneor unspecified => write tostdout)output_format – Format of the output config (optional if file’s extension is recognized)
supplemental_configs – Configs to merge, in order, onto the input
values_needed – Report complete, missing, and template values
dry_run – Log output instead of writing to output
- Returns
True
- uwtools.api.config.realize_to_dict(input_config: Optional[Union[dict, Config, Path, str]] = None, input_format: Optional[str] = None, supplemental_configs: Optional[List[Union[dict, Config, Path, str]]] = None, values_needed: bool = False, dry_run: bool = False) dict
Realize an output config based on an input config and optional supplemental configs.
If no input is specified,
stdinis read. AdictorConfigobject may also be provided as input. When an input filename is specified, its format will be deduced from its extension, if possible. This can be overridden by specifying the format explicitly, and it is required to do so for reads fromstdin, as no attempt is made to deduce the format of streamed data.If optional supplemental configs (which may likewise be file paths or
Config/dictobjects) are provided, they will be merged, in the order specified, onto the input config. The format of all input configs must match.If
values_neededisTrue, a report of values needed to realize the config is logged. Indry_runmode, output is written tostderr.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)
supplemental_configs – Configs to merge, in order, onto the input
values_needed – Report complete, missing, and template values
dry_run – Log output instead of writing to output
- Returns
A
dictrepresenting the realized config
- uwtools.api.config.validate(schema_file: Union[Path, str], config: Optional[Union[dict, YAMLConfig, Path, str]] = None) 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
- Returns
Trueif the YAML file conforms to the schema,Falseotherwise