Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Improve Configuration Management #2

Open
san-ghun opened this issue Nov 20, 2024 · 0 comments
Open

[feat] Improve Configuration Management #2

san-ghun opened this issue Nov 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@san-ghun
Copy link
Owner

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.

@san-ghun san-ghun added the enhancement New feature or request label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant