Skip to content

Convert

sereto.convert

convert_finding_to_tex(finding, render, templates, version, recipe=None)

Convert a file to TeX format using the specified finding, render, templates, version, and recipe.

Parameters:

Name Type Description Default
finding Finding

The finding object representing the file to be converted.

required
render Render

The render object containing convert_recipes and tools for the conversion.

required
templates DirectoryPath

The path to the templates directory.

required
version ProjectVersion

The project version object.

required
recipe str | None

The name of the recipe to use for conversion. Defaults to None.

None

Raises:

Type Description
SeretoValueError

If no converter is found for the specified file format or if the specified recipe is not found.

Returns:

Type Description
None

None

Source code in sereto/convert.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@validate_call
def convert_finding_to_tex(
    finding: Finding,
    render: Render,
    templates: DirectoryPath,
    version: ProjectVersion,
    recipe: str | None = None,
) -> None:
    """Convert a file to TeX format using the specified finding, render, templates, version, and recipe.

    Args:
        finding: The finding object representing the file to be converted.
        render: The render object containing convert_recipes and tools for the conversion.
        templates: The path to the templates directory.
        version: The project version object.
        recipe: The name of the recipe to use for conversion. Defaults to None.

    Raises:
        SeretoValueError: If no converter is found for the specified file format or if the specified recipe is not
            found.

    Returns:
        None
    """

    assert finding.path is not None
    if finding.format == FileFormat.tex:
        return

    convert_recipe = render.get_convert_recipe(name=recipe, input_format=finding.format, output_format=FileFormat.tex)
    finding_file = finding.path / f"{finding.path_name}{version.path_suffix}.{finding.format.value}"

    for tool_name in convert_recipe.tools:
        tool = [t for t in render.tools if t.name == tool_name][0]
        tool.run(
            cwd=finding.path,
            replacements={
                "%DOC%": str(finding_file.resolve().with_suffix("")),
                "%DOC_EXT%": str(finding_file.resolve()),
                "%DOCFILE%": finding_file.resolve().stem,
                "%DOCFILE_EXT%": finding_file.resolve().name,
                "%DIR%": str(finding.path.resolve()),
                "%TEMPLATES%": str(templates),
            },
        )