Remove env var overrides, config.yaml is single source of truth
- Stripped _ENV_MAP and _apply_env_overrides from configs/load.py - Cleaned up unused imports in video_receiver.py - Restored MediaPipe env suppressors in app/main.py - Removed .env.example (replaced by config.yaml)
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
# Server
|
||||
POSEFIT_WS_HOST=0.0.0.0
|
||||
POSEFIT_WS_PORT=8765
|
||||
|
||||
# Video processing
|
||||
POSEFIT_PROCESS_EVERY_N_FRAMES=1
|
||||
|
||||
# Model
|
||||
POSEFIT_MODEL_PATH=pose_models/pose_landmarker_full.task
|
||||
POSEFIT_PREFER_GPU=1
|
||||
|
||||
# Dead bug exercise
|
||||
POSEFIT_VISIBILITY_THRESHOLD=0.45
|
||||
POSEFIT_EXTENSION_CONFIRM_FRAMES=4
|
||||
POSEFIT_RESET_CONFIRM_FRAMES=3
|
||||
|
||||
# Audio
|
||||
POSEFIT_REP_ANNOUNCER_ENABLED=1
|
||||
POSEFIT_REP_ANNOUNCER_RATE=185
|
||||
POSEFIT_REP_ANNOUNCER_VOLUME=1.0
|
||||
|
||||
# Logging
|
||||
POSEFIT_LOG_ROTATION=20 MB
|
||||
POSEFIT_LOG_RETENTION=14 days
|
||||
+1
-1
@@ -12,7 +12,7 @@ def setup_logging() -> None:
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
logger.add(
|
||||
log_dir / "posefit-server_{time:YYYY-MM-DD}.log",
|
||||
log_dir / "{time:YYYY-MM-DD}.log",
|
||||
rotation=config.logging.rotation,
|
||||
retention=config.logging.retention,
|
||||
enqueue=True,
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
os.environ["MEDIAPIPE_DISABLE_LOGGING"] = "1"
|
||||
os.environ["GLOG_minloglevel"] = "3"
|
||||
|
||||
import asyncio
|
||||
|
||||
from loguru import logger
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
import cv2
|
||||
from aiortc.mediastreams import MediaStreamError
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -19,24 +18,6 @@ from configs.models import (
|
||||
|
||||
_PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
_ENV_MAP = {
|
||||
"POSEFIT_WS_HOST": ("server", "host"),
|
||||
"POSEFIT_WS_PORT": ("server", "port", int),
|
||||
"POSEFIT_WS_MAX_SIZE": ("server", "max_ws_size", int),
|
||||
"POSEFIT_PROCESS_EVERY_N_FRAMES": ("video", "process_every_n_frames", int),
|
||||
"POSEFIT_MODEL_PATH": ("model", "path"),
|
||||
"POSEFIT_PREFER_GPU": ("model", "prefer_gpu", lambda v: v not in ("0", "false", "False")),
|
||||
"POSEFIT_VISIBILITY_THRESHOLD": ("dead_bug", "visibility_threshold", float),
|
||||
"POSEFIT_EXTENSION_CONFIRM_FRAMES": ("dead_bug", "extension_confirm_frames", int),
|
||||
"POSEFIT_RESET_CONFIRM_FRAMES": ("dead_bug", "reset_confirm_frames", int),
|
||||
"POSEFIT_REP_ANNOUNCER_ENABLED": ("audio", "rep_announcer_enabled", lambda v: v not in ("0", "false", "False")),
|
||||
"POSEFIT_REP_ANNOUNCER_RATE": ("audio", "rep_announcer_rate", int),
|
||||
"POSEFIT_REP_ANNOUNCER_VOLUME": ("audio", "rep_announcer_volume", float),
|
||||
"POSEFIT_LOG_ROTATION": ("logging", "rotation"),
|
||||
"POSEFIT_LOG_RETENTION": ("logging", "retention"),
|
||||
"POSEFIT_LOG_DIR": ("logging", "dir"),
|
||||
}
|
||||
|
||||
_SECTION_CLASS = {
|
||||
"server": ServerConfig,
|
||||
"video": VideoConfig,
|
||||
@@ -61,22 +42,11 @@ def _read_yaml(path: Path) -> dict[str, Any]:
|
||||
return yaml.safe_load(f) or {}
|
||||
|
||||
|
||||
def _apply_env_overrides(raw: dict[str, Any]) -> None:
|
||||
for env_var, (section, key, *rest) in _ENV_MAP.items():
|
||||
value = os.getenv(env_var)
|
||||
if value is None:
|
||||
continue
|
||||
if rest:
|
||||
value = rest[0](value)
|
||||
raw.setdefault(section, {})[key] = value
|
||||
|
||||
|
||||
def load_config(config_path: str | Path | None = None) -> AppConfig:
|
||||
if config_path is None:
|
||||
config_path = _PROJECT_ROOT / "config.yaml"
|
||||
|
||||
raw = _read_yaml(Path(config_path))
|
||||
_apply_env_overrides(raw)
|
||||
|
||||
return AppConfig(**{
|
||||
section: cls(**_dict_to_dataclass(cls, raw.get(section)))
|
||||
|
||||
Reference in New Issue
Block a user