Skip to content

Build

sereto.build

build_finding_to_tex(project, target, finding, version, converter=None)

Process one finding into TeX format and write it to the ".build" directory.

Source code in sereto/build.py
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
83
84
85
86
87
@validate_call
def build_finding_to_tex(
    project: Project,
    target: Target,
    finding: Finding,
    version: ProjectVersion,
    converter: str | None = None,
) -> None:
    """Process one finding into TeX format and write it to the ".build" directory."""
    # Finding not included in the current version
    if version not in finding.risks:
        Console().log(f"Finding {finding.path_name!r} not found in version {version}. Skipping.")
        return

    # Initialize the build directory
    init_build_dir(project=project, version=version)

    # Process the finding
    content = render_finding_to_tex(
        target,
        finding=finding,
        version=version,
        templates=project.settings.templates_path,
        render=project.settings.render,
        converter=converter,
    )

    # Write the finding to the ".build" directory; do not overwrite the same content (preserve timestamps)
    write_if_different(
        file=project.path / ".build" / target.uname / f"{finding.path_name}{version.path_suffix}.tex",
        content=content,
    )

ensure_finding_group_template(project, target, finding_group, version)

Ensures that a template exists for the specified finding group.

Does not overwrite existing template.

Source code in sereto/build.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@validate_call
def ensure_finding_group_template(
    project: Project, target: Target, finding_group: FindingGroup, version: ProjectVersion
) -> None:
    """Ensures that a template exists for the specified finding group.

    Does not overwrite existing template.
    """
    # Make sure that "layouts/generated" directory exists
    if not (layouts_generated := project.path / "layouts/generated").is_dir():
        layouts_generated.mkdir(parents=True)

    # Create template in "layouts/generated" directory
    template_dst = layouts_generated / f"{target.uname}_{finding_group.uname}{version.path_suffix}.tex.j2"
    if not template_dst.is_file():  # do not overwrite existing templates
        template_src = project.settings.templates_path / "categories" / target.category / "finding_group.tex.j2"
        copy2(template_src, template_dst, follow_symlinks=False)

ensure_target_template(project, target, version)

Ensures that a template exists for the specified target.

Does not overwrite existing template.

Source code in sereto/build.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@validate_call
def ensure_target_template(project: Project, target: Target, version: ProjectVersion) -> None:
    """Ensures that a template exists for the specified target.

    Does not overwrite existing template.
    """
    # Make sure that "layouts/generated" directory exists
    if not (layouts_generated := project.path / "layouts/generated").is_dir():
        layouts_generated.mkdir(parents=True)

    # Create template in "layouts/generated" directory
    template_dst = layouts_generated / f"{target.uname}{version.path_suffix}.tex.j2"
    if not template_dst.is_file():  # do not overwrite existing templates
        template_src = project.settings.templates_path / "categories" / target.category / "target.tex.j2"
        copy2(template_src, template_dst, follow_symlinks=False)