Skip to content

[feat] Improve Configuration Management #2

Description

@san-ghun

The settings management could be improved by:

  • Adding configuration file validation
  • Supporting environment variables override
  • Implementing a proper config parser

Example enhancement for settings.py:

import os
import yaml
from pathlib import Path
from typing import Optional, Dict, Any

def load_config() -> Dict[str, Any]:
    """Load configuration from multiple sources."""
    # Default config
    config = {
        'workspace': os.path.join(os.environ['HOME'], 'Projects/42berlin'),
        'echo_on_startup': True,
        'port_publishing': False,
        'port_host': 8080,
        'port_container': 8080
    }
    
    # Override from config file
    config_file = Path.home() / '.config' / 'tiny42' / 'config.yaml'
    if config_file.exists():
        with open(config_file) as f:
            config.update(yaml.safe_load(f))
    
    # Override from environment variables
    if 'TINY42_WORKSPACE' in os.environ:
        config['workspace'] = os.environ['TINY42_WORKSPACE']
    
    return config

I haven't checked whether the yaml module is a standard module in Python3 or not, as a requirement of the project is to keep external dependencies as low as possible, so I'll switch to using the json module if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions