chore: carry over lab 1 solution into lab 2 skeleton
Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
from .settings import settings
|
||||
|
||||
__all__ = [
|
||||
"settings",
|
||||
]
|
||||
@@ -0,0 +1,75 @@
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Literal
|
||||
|
||||
from pydantic import BaseModel, BeforeValidator, Field
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
PydanticBaseSettingsSource,
|
||||
SettingsConfigDict,
|
||||
TomlConfigSettingsSource,
|
||||
)
|
||||
|
||||
from src.schemas.enums import RunModeEnum
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
ENV_PATH = BASE_DIR.joinpath(".env")
|
||||
TOML_SETTINGS_PATH = BASE_DIR.joinpath("config.toml")
|
||||
|
||||
LogLevel = Annotated[
|
||||
Literal["DEBUG", "INFO", "WARNING", "ERROR"],
|
||||
BeforeValidator(
|
||||
lambda value: value.upper() if isinstance(value, str) else value,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class App(BaseModel):
|
||||
run_mode: RunModeEnum = RunModeEnum.CONSOLE
|
||||
port: int = Field(default=8080, ge=1, le=65535)
|
||||
log_level: LogLevel = "INFO"
|
||||
# секунды, которые uvicorn ждёт текущие запросы после SIGTERM;
|
||||
# docker шлёт SIGKILL через 10 с, поэтому не больше 9
|
||||
graceful_shutdown_seconds: int = Field(default=8, ge=1, le=9)
|
||||
|
||||
@property
|
||||
def host(self) -> str:
|
||||
"""Адрес прослушивания: localhost в console, все интерфейсы в docker."""
|
||||
if self.run_mode == RunModeEnum.DOCKER:
|
||||
return "0.0.0.0"
|
||||
return "127.0.0.1"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
extra="ignore",
|
||||
env_file=ENV_PATH,
|
||||
toml_file=TOML_SETTINGS_PATH,
|
||||
env_nested_delimiter="__",
|
||||
case_sensitive=False,
|
||||
)
|
||||
|
||||
app: App = App()
|
||||
|
||||
@classmethod
|
||||
def settings_customise_sources(
|
||||
cls,
|
||||
settings_cls: type[BaseSettings],
|
||||
init_settings: PydanticBaseSettingsSource,
|
||||
env_settings: PydanticBaseSettingsSource,
|
||||
dotenv_settings: PydanticBaseSettingsSource,
|
||||
file_secret_settings: PydanticBaseSettingsSource, # noqa: ARG003
|
||||
) -> tuple[PydanticBaseSettingsSource, ...]:
|
||||
"""Приоритет: окружение → .env → config.toml → дефолты.
|
||||
|
||||
Оба файловых источника сами пропускают отсутствующий файл: без
|
||||
.env и config.toml сервис поднимается на значениях по умолчанию.
|
||||
"""
|
||||
return (
|
||||
init_settings,
|
||||
env_settings,
|
||||
dotenv_settings,
|
||||
TomlConfigSettingsSource(settings_cls),
|
||||
)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user