Skip to content

models

Pyproject models.

FortranConfig

Bases: BaseModel

Fortran configuration model.

Source code in src/somesy/fortran/models.py
16
17
18
19
20
21
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
class FortranConfig(BaseModel):
    """Fortran configuration model."""

    model_config = dict(use_enum_values=True)

    name: Annotated[
        str,
        Field(pattern=r"^[A-Za-z0-9]+([_-][A-Za-z0-9]+)*$", description="Package name"),
    ]
    version: Annotated[
        Optional[str],
        Field(
            pattern=r"^\d+(\.\d+)*((a|b|rc)\d+)?(post\d+)?(dev\d+)?$",
            description="Package version",
        ),
    ] = None
    description: Annotated[Optional[str], Field(description="Package description")] = (
        None
    )
    license: Annotated[
        Optional[str],
        Field(description="SPDX license identifier(s)."),
    ] = None
    author: Annotated[
        Optional[str], Field(description="Package author information")
    ] = None
    maintainer: Annotated[
        Optional[str], Field(description="Package maintainer information")
    ] = None
    copyright: Annotated[Optional[str], Field(description="Package copyright text")] = (
        None
    )
    homepage: Annotated[Optional[HttpUrlStr], Field(description="Package homepage")] = (
        None
    )
    keywords: Annotated[
        Optional[Set[str]], Field(description="Keywords that describe the package")
    ] = None
    categories: Annotated[
        Optional[Set[str]], Field(description="Categories that package falls into")
    ] = 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

validate_version classmethod

validate_version(v)

Validate version using PEP 440.

Source code in src/somesy/fortran/models.py
58
59
60
61
62
63
64
65
66
@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