nmk_base.common

Python module for nmk-base utility classes.

Module Contents

Classes

TemplateBuilder

Generic builder logic to generate files from templates

MkdirBuilder

Generic builder logic to create directory

class nmk_base.common.TemplateBuilder(model: nmk.model.model.NmkModel)

Bases: nmk.model.builder.NmkTaskBuilder

Generic 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.NmkTaskBuilder

Generic builder logic to create directory

build()

Build logic: create output directory (main output of the task)