or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Configuration File Manager

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.

Requirements

Create a Python module that provides:

  1. A Config class with the following attributes:

    • app_name (str): The application name
    • log_file (Path): Path to the log file
    • data_directory (Path): Path to the data directory
    • backup_paths (list of Path): List of backup directory paths
  2. Two functions:

    • save_config(config: Config, filepath: str) -> None: Serializes the config object to JSON and writes it to the specified file
    • load_config(filepath: str) -> Config: Reads JSON from the specified file and deserializes it back to a Config object

Behavior

  • The Config class should be serializable to JSON format
  • Path objects should be properly serialized to JSON-compatible format
  • When deserializing, strings should be converted back to Path objects
  • The solution should handle both individual Path objects and lists of Path objects

Test Cases

Basic Serialization { .test }

  • Create a Config with app_name="MyApp", log_file=Path("/var/log/app.log"), data_directory=Path("/opt/data"), and backup_paths=[Path("/backup1"), Path("/backup2")]
  • Save the config to a JSON file
  • Verify the JSON file contains string representations of the paths @test

Basic Deserialization { .test }

  • Create a JSON file with config data containing path strings
  • Load the config from the file
  • Verify that log_file, data_directory, and backup_paths are Path objects (not strings)
  • Verify that the Path objects have the correct values @test

Round-Trip { .test }

  • Create a Config object with various paths
  • Save it to a file, then load it back
  • Verify the loaded config is equivalent to the original @test

Implementation

@generates

API

from 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
    """
    pass

Dependencies { .dependencies }

jsons { .dependency }

Provides JSON serialization and deserialization support with pathlib integration.