Skip to content

models

Julia model.

JuliaConfig

Bases: BaseModel

Julia configuration model.

Source code in src/somesy/julia/models.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
class JuliaConfig(BaseModel):
    """Julia configuration model."""

    model_config = dict(use_enum_values=True)

    name: Annotated[
        str,
        Field(description="Package name"),
    ]
    version: Annotated[
        str,
        Field(
            pattern=r"^\d+(\.\d+)*((a|b|rc)\d+)?(post\d+)?(dev\d+)?$",
            description="Package version",
        ),
    ]
    uuid: Annotated[str, Field(description="Package UUID")]
    authors: Annotated[Optional[Set[str]], Field(description="Package authors")] = None

    @field_validator("version")
    @classmethod
    def validate_version(cls, v):
        """Validate version using PEP 440."""
        try:
            _ = parse_version(v)
        except ValueError as err:
            raise ValueError("Invalid version") from err
        return v

    @field_validator("authors")
    @classmethod
    def validate_email_format(cls, v):
        """Validate person format, omit person that is not in correct format, don't raise an error."""
        if v is None:
            return []
        validated = []
        for author in v:
            try:
                if not (
                    not isinstance(author, str)
                    or " " not in author
                    or not EMailAddress.validate_python(author.split(" ")[-1][1:-1])
                ):
                    validated.append(author)
                else:
                    logger.warning(
                        f"Invalid email format for author {author}, omitting."
                    )
            except ValidationError:
                logger.warning(f"Invalid format for author {author}, omitting.")
        return validated

    @field_validator("uuid")
    @classmethod
    def validate_uuid(cls, v):
        """Validate uuid field."""
        try:
            _ = uuid.UUID(v)
        except ValueError as err:
            raise ValueError("Invalid UUID") from err
        return v

validate_version classmethod

validate_version(v)

Validate version using PEP 440.

Source code in src/somesy/julia/models.py
41
42
43
44
45
46
47
48
49
@field_validator("version")
@classmethod
def validate_version(cls, v):
    """Validate version using PEP 440."""
    try:
        _ = parse_version(v)
    except ValueError as err:
        raise ValueError("Invalid version") from err
    return v

validate_email_format classmethod

validate_email_format(v)

Validate person format, omit person that is not in correct format, don't raise an error.

Source code in src/somesy/julia/models.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@field_validator("authors")
@classmethod
def validate_email_format(cls, v):
    """Validate person format, omit person that is not in correct format, don't raise an error."""
    if v is None:
        return []
    validated = []
    for author in v:
        try:
            if not (
                not isinstance(author, str)
                or " " not in author
                or not EMailAddress.validate_python(author.split(" ")[-1][1:-1])
            ):
                validated.append(author)
            else:
                logger.warning(
                    f"Invalid email format for author {author}, omitting."
                )
        except ValidationError:
            logger.warning(f"Invalid format for author {author}, omitting.")
    return validated

validate_uuid classmethod

validate_uuid(v)

Validate uuid field.

Source code in src/somesy/julia/models.py
74
75
76
77
78
79
80
81
82
@field_validator("uuid")
@classmethod
def validate_uuid(cls, v):
    """Validate uuid field."""
    try:
        _ = uuid.UUID(v)
    except ValueError as err:
        raise ValueError("Invalid UUID") from err
    return v