Coverage for src / rustarium / settings.py: 100%
15 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-14 22:19 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-14 22:19 +0000
1"""
2Settings configuration for the rustarium application.
4This module provides the primary configuration structure for the application
5using Pydantic Settings. It aggregates configuration from multiple sources,
6including environment variables and CLI arguments, and exposes a unified interface
7for safe, typed configuration access across the codebase.
8"""
10from __future__ import annotations
12from pathlib import Path
13from typing import ClassVar, Literal
15from pydantic import Field
16from pydantic_settings import (
17 BaseSettings,
18 SettingsConfigDict,
19)
21__all__ = ["Settings"]
24class Settings(BaseSettings):
25 """
26 Configuration state for the application.
28 This class aggregates and prioritizes configuration from multiple sources,
29 providing a unified state for the application. It is built on top of
30 pydantic-settings to allow validation, default values, and type coercion.
32 Example:
33 .. code-block:: python
35 from rustarium.settings import Settings
37 settings = Settings(environment="production")
38 print(settings.project_root)
39 """
41 model_config: ClassVar[SettingsConfigDict] = SettingsConfigDict(
42 arbitrary_types_allowed=True,
43 extra="ignore",
44 populate_by_name=True,
45 validate_assignment=True,
46 env_prefix="RUSTARIUM__",
47 )
48 """Pydantic config dict dictating environment prefixes and validation."""
50 # Core Application Properties
51 project_root: Path = Field(
52 default_factory=Path.cwd,
53 description=(
54 "The root directory of the project. Used for resolving relative paths."
55 ),
56 )
57 environment: Literal["development", "staging", "production"] = Field(
58 default="development",
59 description="The current deployment environment of the application.",
60 )
62 def __str__(self) -> str:
63 """
64 Return a concise string representation of the settings.
66 :return: A concise, human-readable string summary of the settings.
67 :rtype: str
68 """
69 return (
70 f"Settings(environment={self.environment!r}, "
71 f"project_root={self.project_root!r})"
72 )
74 def __repr__(self) -> str:
75 """
76 Return a detailed string representation of the settings.
78 :return: A detailed string representation suitable for debugging.
79 :rtype: str
80 """
81 return (
82 f"Settings("
83 f"environment={self.environment!r}, "
84 f"project_root={self.project_root!r}"
85 f")"
86 )