Add [docs]: add TODOs & other docstrings

This commit is contained in:
Kirill Samoylenkov 2025-10-24 02:26:17 +05:00
parent 9588856a6a
commit f605fac47b
6 changed files with 61 additions and 12 deletions

View file

@ -1 +1,4 @@
__all__ = [] __all__ = []
# TODO: Add automatic import all modules from this folder.

View file

@ -1,6 +1,8 @@
__all__ = [] __all__ = []
# TODO: Add automatic import all modules from this folder.
from aiogram.types import Message from aiogram.types import Message
from bot.handlers import registry from bot.handlers import registry

View file

@ -8,7 +8,42 @@ from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
# Constant paths for project.
LOG_DIR = Path("logs")
LOG_DIR.mkdir(parents=True, exist_ok=True)
# Log format for loguru logger.
LOG_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level:<8}</level> | "
"<cyan>{process}</cyan>.<cyan>{thread.name}</cyan> | "
"<magenta>{module}.{function}:{line}</magenta> "
"<level>{message}</level>"
)
class Settings(BaseSettings): class Settings(BaseSettings):
"""
Class to specify env settings for the project.
The .env file is located in the project root.
Env Vars:
bot_token (str):
Telegram API bot token.
listen_logging (bool):
intercepting logs from logging.
Defaults to False.
file_log_level (Literal):
logging level for the .log file.
"DEBUG", "INFO", "WARNING" or "ERROR".
Defaults to "DEBUG".
console_log_level (Literal):
logging level for the console.
"DEBUG", "INFO", "WARNING" or "ERROR".
Defaults to "INFO".
"""
bot_token: str = Field(frozen=True) bot_token: str = Field(frozen=True)
listen_logging: bool = Field( listen_logging: bool = Field(
@ -43,20 +78,18 @@ class Settings(BaseSettings):
) )
LOG_DIR = Path("logs")
LOG_DIR.mkdir(parents=True, exist_ok=True)
LOG_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level:<8}</level> | "
"<cyan>{process}</cyan>.<cyan>{thread.name}</cyan> | "
"<magenta>{module}.{function}:{line}</magenta> "
"<level>{message}</level>"
)
class InterceptHandler(logging.Handler): class InterceptHandler(logging.Handler):
"""
Class for intercepting logs from logging, including Aiogram.
"""
def emit(self, record: logging.LogRecord) -> None: def emit(self, record: logging.LogRecord) -> None:
"""
Try to intercepting logs from logging.
Args:
record (logging.LogRecord): record from logging.
"""
try: try:
level = loguru_logger.level(record.levelname).name level = loguru_logger.level(record.levelname).name
except ValueError: except ValueError:
@ -82,6 +115,14 @@ def configure_logger(
listen_logging: bool, listen_logging: bool,
console_log_level: str, console_log_level: str,
) -> None: ) -> None:
"""
Configure loguru logger.
Args:
file_log_level (str): logging level for the .log file.
listen_logging (bool): intercepting logs from logging.
console_log_level (str): logging level for the console.
"""
if listen_logging: if listen_logging:
logging.root.handlers.clear() logging.root.handlers.clear()
logging.root.setLevel(logging.DEBUG) logging.root.setLevel(logging.DEBUG)

View file

@ -0,0 +1 @@
# TODO: Add database models.

View file

@ -1,3 +1,4 @@
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
# TODO: Add database session.
session: AsyncSession = ... session: AsyncSession = ...

View file

@ -3,4 +3,5 @@ __all__ = ["client"]
from redis.asyncio.client import Redis from redis.asyncio.client import Redis
# TODO: Add redis client.
client: Redis = ... client: Redis = ...