nmk_base.common
Python module for nmk-base utility classes.
Module Contents
Classes
Common builder logic to generate files from templates |
- class nmk_base.common.TemplateBuilder(model: nmk.model.model.NmkModel)
Bases:
nmk.model.builder.NmkTaskBuilderCommon builder logic to generate files from templates
- relative_path(v: str) str
Make an absolute path as project relative if possible
- Parameters:
v – Path string to be converted
- Returns:
Project relative path (if possible); unchanged input value otherwise
- config_value(config_name: str) Any
Get config value by name & turn absolute paths to project relative ones (if possible)
- Parameters:
config_name – Config item name
- Returns:
Config item value
- render_template(template: pathlib.Path, kwargs: Dict[str, str]) str
Render template into a string, with provided keywords and config items
- Parameters:
template – Path to template file to be rendered
kwargs – Map of keywords for templates rendering, indexed by name
- Returns:
Rendered template string
- Throw:
AssertionError if unknown keyword is referenced in template
- build_from_template(template: pathlib.Path, output: pathlib.Path, kwargs: Dict[str, str]) str
Generate file from template
- Parameters:
template – Path to template file to be rendered
output – Path to output file to be generated
kwargs – Map of keywords for templates rendering, indexed by name
- Returns:
Rendered template string
- Throw:
AssertionError if unknown keyword is referenced in template