from pathlib import Path


def get_datapath(filename, directory=None):
    """ Returns the correct path to JSON files used for assigning attributes

        Args:
            filename (str): Name of JSON file
        Returns:
            pathlib.Path: Path of file
    """

    filename = str(filename)

    if directory is None:
        return Path(__file__).resolve().parent.parent.joinpath(f"Data/{filename}")
    else:
        return (
            Path(__file__)
            .resolve()
            .parent.parent.joinpath(f"Data/{directory}/{filename}")
        )