from typing import Dict
from typing import Any
from pathlib import Path
import yaml
import warnings


def load_config(data_dir, prefix="") -> Dict[str, Any]:
    """Load configuration from YAML file at `data_dir/setting.yaml`

    Args:
        data_dir (str): Directory containing the config file
        prefix (str, optional): Prefix for attribute names in the config dict.
            Defaults to "".

    Returns:
        Dict[str, Any]: Dict containing key/value config
    """
    data_cfg = Path(data_dir) / "settings.yaml"
    params = {}
    if data_cfg.exists():
        with data_cfg.open("rt") as f:
            for k, v in yaml.load(f, Loader=yaml.FullLoader).items():
                params[f"{prefix}{k}"] = v
    else:
        warnings.warn(f"No config for {data_dir}")
    return params