# THEANORC can contain a colon-delimited list of config files, like # THEANORC=~lisa/.theanorc:~/.theanorc # In that case, definitions in files on the right (here, ~/.theanorc) have # precedence over those in files on the left. def config_files_from_theanorc(): rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(os.pathsep)] if os.getenv('THEANORC') is None and sys.platform == "win32": # to don't need to change the filename and make it open easily rval.append(os.path.expanduser('~/.theanorc.txt')) return rval config_files = config_files_from_theanorc() theano_cfg = ConfigParser.SafeConfigParser( {'USER': os.getenv("USER", os.path.split(os.path.expanduser('~'))[-1])} ) theano_cfg.read(config_files) # Having a raw version of the config around as well enables us to pass # through config values that contain format strings. # The time required to parse the config twice is negligible. theano_raw_cfg = ConfigParser.RawConfigParser() theano_raw_cfg.read(config_files) def fetch_val_for_key(key): """Return the overriding config value for a key. A successful search returns a string value. An unsuccessful search raises a KeyError The (decreasing) priority order is:
] if os.getenv('THEANORC') is None and sys.platform == "win32": # to don't need to change the filename and make it open easily rval.append(os.path.expanduser('~/.theanorc.txt')) return rval config_files = config_files_from_theanorc() theano_cfg = ConfigParser.SafeConfigParser({ 'USER': os.getenv("USER", os.path.split(os.path.expanduser('~'))[-1]), 'LSCRATCH': os.getenv("LSCRATCH", ""), 'TMPDIR': os.getenv("TMPDIR", ""), 'TEMP': os.getenv("TEMP", ""), 'TMP': os.getenv("TMP", ""), 'PID': str(os.getpid()), }) theano_cfg.read(config_files) # Having a raw version of the config around as well enables us to pass # through config values that contain format strings. # The time required to parse the config twice is negligible. theano_raw_cfg = ConfigParser.RawConfigParser() theano_raw_cfg.read(config_files)