picongpu.pypicongpu.rendering
Submodules
Classes
helper class to render Mustache templates |
|
Class to be inherited from for rendering context generation |
Package Contents
- class picongpu.pypicongpu.rendering.Renderer
helper class to render Mustache templates
Collection of (static) functions to render Mustache templates.
Also contains checks for structure of passed context (JSON) objects and the JSON schema checks and related functions (loading schema database, checking schemas, looking up schemas by type etc.)
- static check_rendering_context(context: Any) None
check if a context object may be renderd
If checks succeed passes silently, else raises.
Must be used before the preprocessor (as it checks that keys reserved for the preprocessor are not yet used).
Performs if the given object is acceptable as rendering context: - is dict - leafs are string, boolean, None, int, or float (or empty list) - child nodes are leaf, set or list - list items must be dict - keys are strings - keys do not contain dot (.) - keys do not begin with underscore (_) -> reserved for preprocessor
- Parameters:
context – object to be checked
- Raises:
Exception – on check failure
- static get_context_preprocessed(context: dict) dict
preprocess a context object
Applies the following preproccessing to an object: - list items have property “_first” and “_last” (boolean) added - numbers are translated to C++-compatible strings
rejects unchecked rendering contexts
- Parameters:
context – context to be preprocessed
- Returns:
preprocessed copy of context dict
- static get_rendered_template(context: dict, template: str) str
get rendered version of the provided string
Renders a given string using the given context object.
- Parameters:
context – (checked and preprocessed) rendering context
template – string containing template to be rendered
- Returns:
rendered template
- static render_directory(context: dict, path: str) None
Render all templates inside a given directory and remove the templates
Recursively find all files inside given path and render the files ending in “.mustache” to the same name without the ending. The original “.mustache” files are renamed with a dot “.” prefix.
- Parameters:
context – (checked and preprocessed) rendering context
path – directory containing “.mustache” files
- class picongpu.pypicongpu.rendering.RenderedObject
Class to be inherited from for rendering context generation
Every object that intends to generate a rendering context (typically as a dict) must inherit from this class and implement _get_serialized().
It is expected that _get_serialized() fully encodes the internal state, i.e. two equal (==) objects also return an equal result for _get_serialized().
For external usage, the method get_rendering_context() is provided. It passes _get_serialized() through, checking its result against a predefined json schema. If this schema is not fullfilled/not available, an error is raised.
- __hash__()
custom hash function for indexing in dicts
- get_rendering_context() dict | None
get rendering context representation of this object
delegates work to _get_serialized and invokes checks performed by check_context_for_type(). :raise ValidationError: on schema violation :raise RuntimeError: on schema not found :return: self as rendering context
- static check_context_for_type(type_to_check: type, context: dict | None) None
check if the given context is valid for the given type
Raises on error, passes silently if okay.
- Raises:
ValidationError – on schema violation
RuntimeError – on schema not found