def get_default_config_filename():
    """Returns the configuration filepath.

    If PEYOTL_CONFIG_FILE is in the env that is the preferred choice; otherwise ~/.peyotl/config is preferred.
    If the preferred file does not exist, then the packaged peyotl/default.conf from the installation of peyotl is
    used.
    A RuntimeError is raised if that fails.
    """
    global _CONFIG_FN
    if _CONFIG_FN is not None:
        return _CONFIG_FN
    with _CONFIG_FN_LOCK:
        if _CONFIG_FN is not None:
            return _CONFIG_FN
        if 'PEYOTL_CONFIG_FILE' in os.environ:
            cfn = os.path.abspath(os.environ['PEYOTL_CONFIG_FILE'])
        else:
            cfn = os.path.expanduser("~/.peyotl/config")
        if not os.path.isfile(cfn):
            # noinspection PyProtectedMember
            if 'PEYOTL_CONFIG_FILE' in os.environ:
                from peyotl.utility.get_logger import warn_from_util_logger
                msg = 'Filepath "{}" specified via PEYOTL_CONFIG_FILE={} was not found'.format(cfn, os.environ[
                    'PEYOTL_CONFIG_FILE'])
                warn_from_util_logger(msg)
            from pkg_resources import Requirement, resource_filename
            pr = Requirement.parse('peyotl')
            cfn = resource_filename(pr, 'peyotl/default.conf')
        if not os.path.isfile(cfn):
            raise RuntimeError('The peyotl configuration file cascade failed looking for "{}"'.format(cfn))
        _CONFIG_FN = os.path.abspath(cfn)
    return _CONFIG_FN