Skip to content

Renderer

elva.renderer

Module holding renderer components.

Classes:

  • TextRenderer

    Component rendering Y text data types to text files.

TextRenderer(ytext, path, auto_render=True)

Bases: Component

Component rendering Y text data types to text files.

Parameters:

  • ytext (Text) –

    instance of a Y text data type.

Methods:

  • run

    Hook after the component has been started.

  • cleanup

    Hook after the component has been cancelled.

  • write

    Render the contents of ytext to file.

Attributes:

  • ytext (Text) –

    Instance of a Y text data type.

  • path (Path) –

    Path where to store the rendered text file.

  • auto_render (bool) –

    Flag whether to render to text file on hook execution.

Source code in src/elva/renderer.py
def __init__(self, ytext: Text, path: str, auto_render: bool = True):
    """
    Arguments:
        ytext: instance of a Y text data type.
    """
    self.ytext = ytext
    self.path = anyio.Path(path)
    self.auto_render = auto_render

ytext = ytext instance-attribute

Instance of a Y text data type.

path = anyio.Path(path) instance-attribute

Path where to store the rendered text file.

auto_render = auto_render instance-attribute

Flag whether to render to text file on hook execution.

run() async

Hook after the component has been started.

The contents of self.ytext get rendered to file if auto_render is True.

Source code in src/elva/renderer.py
async def run(self):
    """
    Hook after the component has been started.

    The contents of `self.ytext` get rendered to file if [`auto_render`][elva.renderer.TextRenderer.auto_render] is `True`.
    """
    if self.auto_render:
        await self.write()

cleanup() async

Hook after the component has been cancelled.

The contents of self.ytext get rendered to file if auto_render is True.

Source code in src/elva/renderer.py
async def cleanup(self):
    """
    Hook after the component has been cancelled.

    The contents of `self.ytext` get rendered to file if [`auto_render`][elva.renderer.TextRenderer.auto_render] is `True`.
    """
    if self.auto_render:
        await self.write()
        self.log.info(f"saved and closed file {self.path}")

write() async

Render the contents of ytext to file.

Source code in src/elva/renderer.py
async def write(self):
    """
    Render the contents of [`ytext`][elva.renderer.TextRenderer.ytext] to file.
    """
    async with await anyio.open_file(self.path, "w") as self.file:
        self.log.info(f"writing to file {self.path}")
        await self.file.write(str(self.ytext))