nmk_base.common
Python module for nmk-base utility classes.
Module Contents
Classes
Generic builder logic to generate files from templates |
|
Generic builder logic to create directory |
|
Generic builder logic to call a sub-process |
- class nmk_base.common.TemplateBuilder(model: nmk.model.model.NmkModel)
Bases:
nmk.model.builder.NmkTaskBuilderGeneric 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
- build(template: str)
Default build behavior: generate main output file from provided template
- Parameters:
template – Path to the Jinja template to use for generation
- class nmk_base.common.MkdirBuilder(model: nmk.model.model.NmkModel)
Bases:
nmk.model.builder.NmkTaskBuilderGeneric builder logic to create directory
- build()
Build logic: create specified directory (main output of the task)
- class nmk_base.common.ProcessBuilder(model: nmk.model.model.NmkModel)
Bases:
nmk.model.builder.NmkTaskBuilderGeneric builder logic to call a sub-process
- build(cmd: str | List[str], verbose: bool = False)
Build logic:
call subprocess specified through cmd parameter; process is invoked in project directory
depending on the verbose parameter, redirect output to stdout (if True) or to nmk logs (if False)
touch the specified output file
- Parameters:
cmd – process command line; may be a string or a list of parameters
verbose – states if the process output shall be displayed in stdout or saved in logs