import zipfile
import json


def load_SMLM_manifest(path):
    """
    Read manifest.json (version 0.2) from a SMLM single-molecule localization (zip) file.

    Parameters
    ----------
    path : str, bytes, os.PathLike, file-like
        File path for a SMLM file to load.

    Returns
    -------
    dictionary
        manifest in json format
    """
    zf = zipfile.ZipFile(path, "r")
    file_names = zf.namelist()
    if "manifest.json" not in file_names:
        raise Exception("invalid file: no manifest.json found in the smlm file.")
    manifest = json.loads(zf.read("manifest.json"))
    assert manifest["format_version"] == "0.2"
    return manifest