# Path: hypergolix/exceptions.py
# class ConfigError(HypergolixException, RuntimeError):
#     ''' This exception (or a subclass thereof) is raised for all failed
#     operations with configuration.
#     '''
#     pass
# 
# Path: hypergolix/exceptions.py
# class ConfigIncomplete(ConfigError):
#     ''' This exception is raised when attempting to load an incomplete
#     configuration.
#     '''
#     pass
# 
# Path: hypergolix/exceptions.py
# class ConfigMissing(ConfigError, FileNotFoundError):
#     ''' This exception is raised when attempting to load an incomplete
#     configuration.
#     '''
#     pass


import pathlib
import collections
import copy
import webbrowser
import yaml
import inspect
import os
import warnings
import logging
from golix import Ghid
from golix import Secret
from .exceptions import ConfigError
from .exceptions import ConfigIncomplete
from .exceptions import ConfigMissing
        # Get the environment config setting, if it exists. If not, use a
        # long random path which we "know" will not exist.
        envpath = os.getenv(
            'HYPERGOLIX_HOME',
            default = '/qdubuddfsyvfafhlqcqetfkokykqeulsguoasnzjkc'
        )
        appdatapath = os.getenv(
            'LOCALAPPDATA',
            default = '/qdubuddfsyvfafhlqcqetfkokykqeulsguoasnzjkc'
        )
        
        search_order = []
        search_order.append(pathlib.Path(envpath))
        search_order.append(pathlib.Path('.').absolute())
        search_order.append(pathlib.Path.home() / '.hypergolix')
        # It really doesn't matter if we do this on Windows too, since it'll
        # just not exist.
        search_order.append(pathlib.Path('/etc/hypergolix'))
        search_order.append(pathlib.Path(appdatapath) / 'Hypergolix')
        
        # Collapse the nested loop into a single for loop with a list comp
        fnames = {cls.TARGET_FNAME, *cls.OLD_FNAMES}
        fpaths = (dirpath / fname for dirpath in search_order
                  for fname in fnames)
        # Check all of those paths
        for fpath in fpaths:
            if fpath.exists():
                break
        # Not found; raise.
        else:

# Path: hypergolix/exceptions.py
# class ConfigError(HypergolixException, RuntimeError):
#     ''' This exception (or a subclass thereof) is raised for all failed
#     operations with configuration.
#     '''
#     pass
# 
# Path: hypergolix/exceptions.py
# class ConfigIncomplete(ConfigError):
#     ''' This exception is raised when attempting to load an incomplete
#     configuration.
#     '''
#     pass
# 
# Path: hypergolix/exceptions.py
# class ConfigMissing(ConfigError, FileNotFoundError):
#     ''' This exception is raised when attempting to load an incomplete
#     configuration.
#     '''
#     pass


# Path: hypergolix/config.py
import pathlib
import collections
import copy
import webbrowser
import yaml
import inspect
import os
import warnings
import logging
from golix import Ghid
from golix import Secret
from .exceptions import ConfigError
from .exceptions import ConfigIncomplete
from .exceptions import ConfigMissing

        # Get the environment config setting, if it exists. If not, use a
        # long random path which we "know" will not exist.
        envpath = os.getenv(
            'HYPERGOLIX_HOME',
            default = '/qdubuddfsyvfafhlqcqetfkokykqeulsguoasnzjkc'
        )
        appdatapath = os.getenv(
            'LOCALAPPDATA',
            default = '/qdubuddfsyvfafhlqcqetfkokykqeulsguoasnzjkc'
        )
        
        search_order = []
        search_order.append(pathlib.Path(envpath))
        search_order.append(pathlib.Path('.').absolute())
        search_order.append(pathlib.Path.home() / '.hypergolix')
        # It really doesn't matter if we do this on Windows too, since it'll
        # just not exist.
        search_order.append(pathlib.Path('/etc/hypergolix'))
        search_order.append(pathlib.Path(appdatapath) / 'Hypergolix')
        
        # Collapse the nested loop into a single for loop with a list comp
        fnames = {cls.TARGET_FNAME, *cls.OLD_FNAMES}
        fpaths = (dirpath / fname for dirpath in search_order
                  for fname in fnames)
        # Check all of those paths
        for fpath in fpaths:
            if fpath.exists():
                break
        # Not found; raise.
        else:

            raise ConfigMissing()