# Path: cotede/utils/utils.py
# def cotederc(subdir=None):
#     """Directory with custom configuration for CoTeDe
# 
#     To keep the local environment tight, CoTeDe expects to find all local files,
#     like pre-set QC procedures, in one single place. This function returns the
#     path to that directory.
# 
#     Parameters
#     ----------
#     subdir : str, optional
#         Sub-directory inside the base custom directory.
# 
#     Returns
#     -------
#     str
#         A path to the local custom files.
# 
#         The default path is a directory at the user's home like::
# 
#             ~/.config/cotederc/
# 
#     Note
#     ----
#     That default path can be modified by defining the environment variable
#     COTEDE_DIR. On bash that could be done like::
# 
#         export COTEDE_DIR='/my/other/awesome/path/'
# 
#     Note
#     ----
#     For windows users the path is automatically adjusted to reflect its
#     syntax.
# 
#     Example
#     -------
#     A sub-directory for configuration files, named 'cfg', can be determined by::
# 
#     >>> cotederc('cfg')
#     """
#     path = os.getenv("COTEDE_DIR", os.path.join("~", ".config", "cotederc"))
#     path = os.path.expanduser(path)
#     if subdir is not None:
#         path = os.path.join(path, subdir)
#     return path


from collections import OrderedDict
from .utils import cotederc
import copy
import json
import logging
import os.path
import pkg_resources
    -------
    cfg : OrderedDict
        A dictionary defining a full QC procedure that defines which tests to
        run on which variables.

    See also
    --------
    utils.list_cfgs
    """
    if cfgname is None:
        cfgname = "cotede"

    assert isinstance(
        cfgname, (dict, str)
    ), "load_cfg() input must be a dictionary or a str"

    # A given manual configuration has priority
    if isinstance(cfgname, dict):
        module_logger.debug("User's QC cfg: %s" % cfgname)
        cfg = OrderedDict(copy.deepcopy(cfgname))
    elif isinstance(cfgname, str):
        try:
            # If cfg is available in builtin options, use it
            p = pkg_resources.resource_string(
                "cotede", os.path.join("qc_cfg", "{}.json".format(cfgname))
            )
            cfg = json.loads(p, object_pairs_hook=OrderedDict)
            module_logger.debug("Builtin config - %s" % cfgname)
        except:
            # Otherwise, try to load from user's directory

# Path: cotede/utils/utils.py
# def cotederc(subdir=None):
#     """Directory with custom configuration for CoTeDe
# 
#     To keep the local environment tight, CoTeDe expects to find all local files,
#     like pre-set QC procedures, in one single place. This function returns the
#     path to that directory.
# 
#     Parameters
#     ----------
#     subdir : str, optional
#         Sub-directory inside the base custom directory.
# 
#     Returns
#     -------
#     str
#         A path to the local custom files.
# 
#         The default path is a directory at the user's home like::
# 
#             ~/.config/cotederc/
# 
#     Note
#     ----
#     That default path can be modified by defining the environment variable
#     COTEDE_DIR. On bash that could be done like::
# 
#         export COTEDE_DIR='/my/other/awesome/path/'
# 
#     Note
#     ----
#     For windows users the path is automatically adjusted to reflect its
#     syntax.
# 
#     Example
#     -------
#     A sub-directory for configuration files, named 'cfg', can be determined by::
# 
#     >>> cotederc('cfg')
#     """
#     path = os.getenv("COTEDE_DIR", os.path.join("~", ".config", "cotederc"))
#     path = os.path.expanduser(path)
#     if subdir is not None:
#         path = os.path.join(path, subdir)
#     return path


# Path: cotede/utils/config.py
from collections import OrderedDict
from .utils import cotederc
import copy
import json
import logging
import os.path
import pkg_resources

    -------
    cfg : OrderedDict
        A dictionary defining a full QC procedure that defines which tests to
        run on which variables.

    See also
    --------
    utils.list_cfgs
    """
    if cfgname is None:
        cfgname = "cotede"

    assert isinstance(
        cfgname, (dict, str)
    ), "load_cfg() input must be a dictionary or a str"

    # A given manual configuration has priority
    if isinstance(cfgname, dict):
        module_logger.debug("User's QC cfg: %s" % cfgname)
        cfg = OrderedDict(copy.deepcopy(cfgname))
    elif isinstance(cfgname, str):
        try:
            # If cfg is available in builtin options, use it
            p = pkg_resources.resource_string(
                "cotede", os.path.join("qc_cfg", "{}.json".format(cfgname))
            )
            cfg = json.loads(p, object_pairs_hook=OrderedDict)
            module_logger.debug("Builtin config - %s" % cfgname)
        except:
            # Otherwise, try to load from user's directory

            p = os.path.join(cotederc("cfg"), "{}.json".format(cfgname))