1#
2# This loads the configuration
3#
4import os
5try:
6    #Attempt Python 2 ConfigParser setup
7    import ConfigParser
8    config = ConfigParser.ConfigParser()
9    from ConfigParser import NoOptionError
10except ImportError:
11    #Attempt Python 3 ConfigParser setup
12    import configparser
13    config = configparser.ConfigParser()
14    from configparser import NoOptionError
15
16# This is the default configuration file that always needs to be present.
17default_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'defaults.cfg'))
18
19# These files are optional
20# This specifies configurations that are typically specific to the machine (it is found alongside the GPy installation).
21local_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'installation.cfg'))
22
23# This specifies configurations specific to the user (it is found in the user home directory)
24home = os.getenv('HOME') or os.getenv('USERPROFILE') or ''
25user_file = os.path.join(home,'.config','GPy', 'user.cfg')
26
27# Read in the given files.
28config.readfp(open(default_file))
29config.read([local_file, user_file])
30
31if not config:
32    raise ValueError("No configuration file found at either " + user_file + " or " + local_file + " or " + default_file + ".")
33