feat: Enhance tddai configuration with auto-loading .env files
Configuration System Improvements: - Add automatic .env.tddai file loading without external dependencies - Implement load_dotenv_file() helper for lightweight env file parsing - Maintain configuration hierarchy: Environment → .env.tddai → Defaults - Zero breaking changes - existing setup script approach still works Documentation: - Create comprehensive CONFIG.md with configuration management guide - Document hierarchy, options, platform examples, and troubleshooting - Include migration instructions and best practices - Cover both auto-loading and manual configuration methods Benefits: - Users no longer need to manually source setup scripts - Project-agnostic configuration system remains flexible - Improved developer experience with seamless config loading - Complete documentation for configuration management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,19 @@ from dataclasses import dataclass
|
||||
from .exceptions import ConfigurationError
|
||||
|
||||
|
||||
def load_dotenv_file(env_file: Path) -> None:
|
||||
"""Load environment variables from a .env file."""
|
||||
if not env_file.exists():
|
||||
return
|
||||
|
||||
with open(env_file, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
os.environ.setdefault(key.strip(), value.strip())
|
||||
|
||||
|
||||
@dataclass
|
||||
class TddaiConfig:
|
||||
"""Configuration settings for tddai."""
|
||||
@@ -58,7 +71,11 @@ class TddaiConfig:
|
||||
|
||||
@classmethod
|
||||
def from_environment(cls) -> "TddaiConfig":
|
||||
"""Create config from environment variables."""
|
||||
"""Create config from environment variables and .env files."""
|
||||
# Auto-load .env.tddai file if it exists
|
||||
env_file = Path(".env.tddai")
|
||||
load_dotenv_file(env_file)
|
||||
|
||||
config = cls()
|
||||
|
||||
# Override with environment variables if present
|
||||
|
||||
Reference in New Issue
Block a user