from pathlib import Path


def get_set_local_dir(basename='pymodaq_local'):
    """Defines, creates abd returns a local folder where configurations files will be saved

    Parameters
    ----------
    basename: (str) how the configuration folder will be named

    Returns
    -------
    Path: the local path
    """
    local_path = Path.home().joinpath(basename)

    if not local_path.is_dir():                            # pragma: no cover
        try:
            local_path.mkdir()
        except Exception as e:
            local_path = Path(__file__).parent.parent.joinpath(basename)
            info = f"Cannot create local folder from your **Home** defined location: {Path.home()}," \
                   f" using PyMoDAQ's folder as local directory: {local_path}"
            print(info)
            if not local_path.is_dir():
                local_path.mkdir()
    return local_path