from pathlib import Path
import json


def import_batch_config(filepath):
    """
    Import a batch configuration file.

    Parameters
    -----------
    filepath : :class:`str` | :class:`pathlib.Path`

    Returns
    ---------
    :class:`dict`
        Configuration dictionary indexed by hashes.
    """

    filepath = Path(filepath)
    if filepath.is_dir():
        # find config
        cfgpath = filepath / "meltsBatchConfig.json"
    else:
        cfgpath = filepath.with_suffix("json")

    with open(str(cfgpath), "r") as f:
        cfg = json.loads(f.read())
    return cfg