Skip to content

Config

sereto.models.config

ConfigModel

Bases: SeretoBaseModel

Model representing the full project configuration in config.json file.

Attributes:

Name Type Description
sereto_version SeretoVersion

Version of SeReTo which produced the config.

version_configs dict[ProjectVersion, VersionConfigModel]

Configuration for each version of the Project.

Source code in sereto/models/config.py
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
class ConfigModel(SeretoBaseModel):
    """Model representing the full project configuration in config.json file.

    Attributes:
        sereto_version: Version of SeReTo which produced the config.
        version_configs: Configuration for each version of the Project.
    """

    sereto_version: SeretoVersion
    version_configs: dict[ProjectVersion, VersionConfigModel]

    @classmethod
    @validate_call
    def load_from(cls, file: FilePath) -> Self:
        """Load the configuration from a JSON file.

        Args:
            file: The path to the configuration file.

        Returns:
            The configuration object.

        Raises:
            SeretoPathError: If the file is not found or permission is denied.
            SeretoValueError: If the configuration is invalid.
        """
        try:
            return cls.model_validate_json(file.read_bytes())
        except FileNotFoundError:
            raise SeretoPathError(f"file not found at '{file}'") from None
        except PermissionError:
            raise SeretoPathError(f"permission denied for '{file}'") from None
        except ValidationError as e:
            raise SeretoValueError(f"invalid config\n\n{e}") from e

load_from(file) classmethod

Load the configuration from a JSON file.

Parameters:

Name Type Description Default
file FilePath

The path to the configuration file.

required

Returns:

Type Description
Self

The configuration object.

Raises:

Type Description
SeretoPathError

If the file is not found or permission is denied.

SeretoValueError

If the configuration is invalid.

Source code in sereto/models/config.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@classmethod
@validate_call
def load_from(cls, file: FilePath) -> Self:
    """Load the configuration from a JSON file.

    Args:
        file: The path to the configuration file.

    Returns:
        The configuration object.

    Raises:
        SeretoPathError: If the file is not found or permission is denied.
        SeretoValueError: If the configuration is invalid.
    """
    try:
        return cls.model_validate_json(file.read_bytes())
    except FileNotFoundError:
        raise SeretoPathError(f"file not found at '{file}'") from None
    except PermissionError:
        raise SeretoPathError(f"permission denied for '{file}'") from None
    except ValidationError as e:
        raise SeretoValueError(f"invalid config\n\n{e}") from e

VersionConfigModel

Bases: SeretoBaseModel

Model with core attributes for a specific version of the project configuration.

Attributes:

Name Type Description
id str

The ID of the project.

name str

The name of the project.

version_description str

The description of the version (e.g. "retest").

targets list[TargetModel]

List of targets.

dates list[Date]

List of dates.

people list[Person]

List of people.

Source code in sereto/models/config.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class VersionConfigModel(SeretoBaseModel):
    """Model with core attributes for a specific version of the project configuration.

    Attributes:
        id: The ID of the project.
        name: The name of the project.
        version_description: The description of the version (e.g. "retest").
        targets: List of targets.
        dates: List of dates.
        people: List of people.
    """

    id: str
    name: str
    version_description: str
    targets: list[TargetModel] = Field(default_factory=list)
    dates: list[Date] = Field(default_factory=list)
    people: list[Person] = Field(default_factory=list)

    @model_validator(mode="after")
    def unique_target_names(self) -> Self:
        unames = [target.uname for target in self.targets]
        if len(unames) != len(set(unames)):
            raise ValueError("duplicate target uname")
        return self