Skip to content

mecfs_bio.build_system.task.typst_source

A Typst diagram source: exactly one of a committed .typ file path or an inline string of Typst code.

Classes:

  • TypstSource –

    Holds exactly one of a path to a .typ file or a literal string of Typst

TypstSource

Holds exactly one of a path to a .typ file or a literal string of Typst code. Enforcing exactly-one at construction makes the invalid states (both set, neither set, missing file) unrepresentable.

Methods:

  • resolve_to_path –

    Return a concrete .typ path for the source. For the path variant this is

Attributes:

code class-attribute instance-attribute

code: str | None = None

path class-attribute instance-attribute

path: Path | None = None

resolve_to_path

resolve_to_path(scratch_dir: Path) -> Path

Return a concrete .typ path for the source. For the path variant this is the existing file; for the code variant the string is written into scratch_dir and that new path is returned.

Source code in mecfs_bio/build_system/task/typst_source.py
def resolve_to_path(self, scratch_dir: Path) -> Path:
    """
    Return a concrete .typ path for the source. For the path variant this is
    the existing file; for the code variant the string is written into
    scratch_dir and that new path is returned.
    """
    if self.path is not None:
        return self.path
    assert self.code is not None  # guaranteed by __attrs_post_init__
    target = scratch_dir / _SOURCE_FILENAME
    target.write_text(self.code)
    return target