uwtools.api.template
- uwtools.api.template.render(values: Union[dict, Path, str], values_format: Optional[str] = None, input_file: Optional[Union[Path, str]] = None, output_file: Optional[Union[Path, str]] = None, overrides: Optional[Dict[str, str]] = None, values_needed: bool = False, dry_run: bool = False) bool
Render a Jinja2 template based on specified values.
Primary values used to render the template are taken from the specified file. The format of the values source will be deduced from the filename extension, if possible. This can be overridden via the
values_formatargument. Adictobject may alternatively be provided as the primary values source. If no input file is specified,stdinis read. If no output file is specified,stdoutis written to.- Parameters
values – Source of values to render the template
values_format – Format of values when sourced from file
input_file – Path to read raw Jinja2 template from (
Noneor unspecified => readstdin)output_file – Path to write rendered Jinja2 template to (
Noneor unspecified => write tostdout)overrides – Supplemental override values
values_needed – Just report variables needed to render the template?
dry_run – Run in dry-run mode?
- Returns
Trueif Jinja2 template was successfully rendered,Falseotherwise
- uwtools.api.template.translate(input_file: Optional[Union[Path, str]] = None, output_file: Optional[Union[Path, str]] = None, dry_run: bool = False) bool
Translate an atparse template to a Jinja2 template.
@[]tokens are replaced with Jinja2{{}}equivalents. If no input file is specified,stdinis read. If no output file is specified,stdoutis written to. Indry_runmode, output is written tostderr.- Parameters
input_file – Path to the template containing atparse syntax
output_file – Path to the file to write the converted template to
dry_run – Run in dry-run mode?
- Returns
True