docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a configuration file manager that handles application settings with file path support. The manager should serialize and deserialize configuration objects that contain file paths, ensuring paths are properly handled across different systems.
Create a Python module that provides:
A Config class with the following attributes:
app_name (str): The application namelog_file (Path): Path to the log filedata_directory (Path): Path to the data directorybackup_paths (list of Path): List of backup directory pathsTwo functions:
save_config(config: Config, filepath: str) -> None: Serializes the config object to JSON and writes it to the specified fileload_config(filepath: str) -> Config: Reads JSON from the specified file and deserializes it back to a Config objectfrom pathlib import Path
from typing import List
class Config:
"""Configuration object containing application settings with file paths."""
def __init__(self, app_name: str, log_file: Path, data_directory: Path, backup_paths: List[Path]):
self.app_name = app_name
self.log_file = log_file
self.data_directory = data_directory
self.backup_paths = backup_paths
def save_config(config: Config, filepath: str) -> None:
"""
Serialize a Config object to JSON and write to file.
Args:
config: The Config object to serialize
filepath: Path to the output JSON file
"""
pass
def load_config(filepath: str) -> Config:
"""
Load a Config object from a JSON file.
Args:
filepath: Path to the JSON file to read
Returns:
Config: The deserialized Config object
"""
passProvides JSON serialization and deserialization support with pathlib integration.