Skip to content

Settings

sereto.settings

is_settings_valid(print=False)

Check if the settings are valid.

Parameters:

Name Type Description Default
print bool

Whether to print the validation status. Defaults to False.

False

Returns:

Type Description
bool

True if the settings are valid, False otherwise.

Source code in sereto/settings.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
@validate_call
def is_settings_valid(print: bool = False) -> bool:
    """Check if the settings are valid.

    Args:
        print: Whether to print the validation status. Defaults to False.

    Returns:
        True if the settings are valid, False otherwise.
    """
    try:
        Settings.model_validate_json(Settings.get_path().read_bytes())
        if print:
            Console().log("[green]Settings are valid")
        return True
    except ValidationError:
        if print:
            Console().log("[red]Settings are invalid")
        return False

load_settings(f)

Decorator which calls load_settings_function and provides Settings as the first argument

Source code in sereto/settings.py
18
19
20
21
22
23
24
25
26
def load_settings(f: Callable[P, R]) -> Callable[P, R]:
    """Decorator which calls `load_settings_function` and provides Settings as the first argument"""

    @wraps(f)
    def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
        settings = load_settings_function()
        return get_current_context().invoke(f, settings, *args, **kwargs)

    return wrapper

write_settings(settings)

Write settings to a standard system location.

Parameters:

Name Type Description Default
settings Settings

The Settings object to write.

required
Source code in sereto/settings.py
71
72
73
74
75
76
77
78
79
80
81
82
83
@validate_call
def write_settings(settings: Settings) -> None:
    """Write settings to a standard system location.

    Args:
        settings: The Settings object to write.
    """
    settings_path = Settings.get_path()
    settings_path.parent.mkdir(parents=True, exist_ok=True)

    with settings_path.open("w", encoding="utf-8") as f:
        f.write(settings.model_dump_json(indent=2, exclude_defaults=True))
        f.write("\n")