
- Added proper type annotations for DB_DIR using ClassVar[Path] - Updated Settings class to use model_config instead of deprecated Config class - Fixed PydanticUserError for non-annotated attributes in settings - Application should now start properly with uvicorn
33 lines
820 B
Python
33 lines
820 B
Python
import os
|
|
from pathlib import Path
|
|
from typing import ClassVar
|
|
|
|
from pydantic_settings import BaseSettings
|
|
|
|
# Build paths inside the project
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Todo App API"
|
|
PROJECT_DESCRIPTION: str = (
|
|
"A simple Todo application API built with FastAPI and SQLite"
|
|
)
|
|
VERSION: str = "0.1.0"
|
|
|
|
# SQLite Database settings
|
|
DB_DIR: ClassVar[Path] = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
model_config = {
|
|
"case_sensitive": True,
|
|
"env_file": os.path.join(BASE_DIR, ".env"),
|
|
}
|
|
|
|
|
|
settings = Settings()
|
|
|
|
# Ensure database directory exists
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|