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.
The settings management could be improved by:
Example enhancement for settings.py:
I haven't checked whether the
yamlmodule 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 thejsonmodule if necessary.