Skip to content

Settings

sereto.models.settings

ConvertRecipe

Bases: RenderRecipe

Recipe for converting between file formats using RenderTools.

Attributes:

Name Type Description
name

name of the recipe

input_format FileFormat

input file format

tools FileFormat

list of RenderTool names to run

Source code in sereto/models/settings.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class ConvertRecipe(RenderRecipe):
    """Recipe for converting between file formats using `RenderTool`s.

    Attributes:
        name: name of the recipe
        input_format: input file format
        tools: list of `RenderTool` names to run
    """

    input_format: FileFormat

    @field_validator("input_format", mode="before")
    @classmethod
    def load_input_format(cls, v: Any) -> FileFormat:
        match v:
            case FileFormat():
                return v
            case str():
                return FileFormat(v)
            case _:
                raise ValueError("invalid type for input_format")

RenderRecipe

Bases: SeretoBaseModel

Recipe for rendering and converting files using RenderTools.

Attributes:

Name Type Description
name str

name of the recipe

tools list[str]

list of RenderTool names to run

Source code in sereto/models/settings.py
22
23
24
25
26
27
28
29
30
31
class RenderRecipe(SeretoBaseModel):
    """Recipe for rendering and converting files using `RenderTool`s.

    Attributes:
        name: name of the recipe
        tools: list of `RenderTool` names to run
    """

    name: str
    tools: list[str] = Field(..., min_length=1)

RenderTool

Bases: SeretoBaseModel

Commands used in recipes.

Attributes:

Name Type Description
name str

name of the tool

command str

command to run

args list[str]

list of arguments to pass to the command

Source code in sereto/models/settings.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class RenderTool(SeretoBaseModel):
    """Commands used in recipes.

    Attributes:
        name: name of the tool
        command: command to run
        args: list of arguments to pass to the command
    """

    name: str
    command: str
    args: list[str]

    @validate_call
    def run(self, cwd: Path, replacements: dict[str, str] | None = None) -> None:
        command = [self.command] + self.args
        if replacements is not None:
            command = replace_strings(text=command, replacements=replacements)
        Console().log(f"Running command: {' '.join(command)}")
        run(command, cwd=cwd)

Settings

Bases: SeretoBaseSettings

Global settings:

Attributes:

Name Type Description
reports_path DirectoryPath

path to the directory containing all reports

templates_path DirectoryPath

path to the directory containing templates

render Render

rendering settings

categories TypeCategories

supported categories - list of strings (2-20 lower-alpha characters; also dash and underscore is possible in all positions except the first and last one)

Source code in sereto/models/settings.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
class Settings(SeretoBaseSettings):
    """Global settings:

    Attributes:
        reports_path: path to the directory containing all reports
        templates_path: path to the directory containing templates
        render: rendering settings
        categories: supported categories - list of strings (2-20 lower-alpha characters; also dash and underscore is
            possible in all positions except the first and last one)
    """

    reports_path: DirectoryPath
    templates_path: DirectoryPath
    render: Render = Field(default=DEFAULT_RENDER_CONFIG)
    categories: TypeCategories = Field(default=DEFAULT_CATEGORIES)

    @staticmethod
    def get_path() -> Path:
        return Path(get_app_dir(app_name="sereto")) / "settings.json"

    @classmethod
    def from_file(cls, filepath: Path) -> "Settings":
        try:
            return cls.model_validate_json(filepath.read_bytes())
        except FileNotFoundError:
            raise SeretoPathError(f'file not found at "{filepath}"') from None
        except PermissionError:
            raise SeretoPathError(f'permission denied for "{filepath}"') from None
        except ValueError as e:
            raise SeretoValueError("invalid settings") from e