""" Configuration module for gesture detection system. Handles environment variables and logfire token configuration. """ import os from pathlib import Path from typing import Optional def get_logfire_token() -> Optional[str]: """ Get the logfire token from environment variables or local configuration. Priority order: 1. LOGFIRE_TOKEN environment variable (for production/deployment) 2. .env file in project root (for local development) 3. None (monitoring disabled) Returns ------- Optional[str] The logfire token if found, None otherwise """ # First check environment variable (for production) token = os.getenv("LOGFIRE_TOKEN") if token: return token # Check for .env file in project root (for local development) env_file = Path(__file__).parent.parent.parent / ".env" if env_file.exists(): try: with open(env_file, "r") as f: for line in f: line = line.strip() if line.startswith("LOGFIRE_TOKEN="): return line.split("=", 1)[1].strip('"\'') except Exception: # If we can't read the .env file, continue without token pass return None def is_monitoring_enabled() -> bool: """ Check if monitoring is enabled by checking if we have a logfire token. Returns ------- bool True if monitoring is enabled, False otherwise """ return get_logfire_token() is not None