VCS settings
This commit is contained in:
parent
b18488a6d3
commit
1d615e9f7d
1 changed files with 11 additions and 3 deletions
|
|
@ -1,18 +1,25 @@
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
|
||||||
class AppConfig(BaseModel):
|
class AppConfig(BaseModel):
|
||||||
host: str = "127.0.0.1"
|
host: str = "127.0.0.1"
|
||||||
port: int = 8000
|
port: int = 8000
|
||||||
reload: bool = True
|
reload: bool = True
|
||||||
|
|
||||||
|
class GitConfig(BaseModel):
|
||||||
|
directory: str = "/opt/repo/sample"
|
||||||
|
branch: str = "master"
|
||||||
|
remote: str = "origin"
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_prefix="KARL_", env_nested_delimiter="__")
|
model_config = SettingsConfigDict(env_prefix="KARL_", env_nested_delimiter="__")
|
||||||
app: AppConfig = AppConfig()
|
app: AppConfig = AppConfig()
|
||||||
|
git: GitConfig = GitConfig()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, path: Path | str = "config/config.yaml") -> "Settings":
|
def from_yaml(cls, path: Path | str = "config/config.yaml") -> "Settings":
|
||||||
|
|
@ -23,6 +30,7 @@ class Settings(BaseSettings):
|
||||||
data = yaml.safe_load(fh) or {}
|
data = yaml.safe_load(fh) or {}
|
||||||
return cls(**data)
|
return cls(**data)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def get_settings() -> Settings:
|
def get_settings() -> Settings:
|
||||||
return Settings.from_yaml()
|
return Settings.from_yaml()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue