提交 1c90389e authored 作者: Pascal Lamblin's avatar Pascal Lamblin

THEANO_FLAGS and THEANORC environment variables are now right-dominant…

THEANO_FLAGS and THEANORC environment variables are now right-dominant (right-most definitions have precedence over the ones on their left)
上级 5fba2f7c
...@@ -14,11 +14,12 @@ THEANO_FLAGS=os.getenv("THEANO_FLAGS","") ...@@ -14,11 +14,12 @@ THEANO_FLAGS=os.getenv("THEANO_FLAGS","")
# [section.]option[=value] entries. If the section part is omited, their should be only one # [section.]option[=value] entries. If the section part is omited, their should be only one
# section with that contain the gived option. # section with that contain the gived option.
# THEANORC=~/.theanorc:~lisa/.theanorc # 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(): def config_files_from_theanorc():
rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(':')] rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(':')]
rval.reverse()
print "THEANORC", rval
return rval return rval
theano_cfg = ConfigParser.SafeConfigParser() theano_cfg = ConfigParser.SafeConfigParser()
theano_cfg.read(config_files_from_theanorc()) theano_cfg.read(config_files_from_theanorc())
...@@ -42,14 +43,15 @@ def fetch_val_for_key(key): ...@@ -42,14 +43,15 @@ def fetch_val_for_key(key):
"""Return the overriding config value for a key. """Return the overriding config value for a key.
A successful search returs a string value. A successful search returs a string value.
An unsuccessful search raises a KeyError An unsuccessful search raises a KeyError
The priority order is: The (decreasing) priority order is:
- THEANO_FLAGS - THEANO_FLAGS
- ~./theanorc - ~./theanorc
""" """
# first try to find it in the FLAGS # first try to find it in the FLAGS
rval = None
for name_val in THEANO_FLAGS.split(','): for name_val in THEANO_FLAGS.split(','):
if not name_val: if not name_val:
continue continue
...@@ -60,7 +62,12 @@ def fetch_val_for_key(key): ...@@ -60,7 +62,12 @@ def fetch_val_for_key(key):
name, val = name_val_tuple name, val = name_val_tuple
if name == key: if name == key:
return val # rval might be overriden by a later definition in THEANO_FLAGS
rval = val
# If an rval is found, it should be a string
if rval is not None:
return rval
# next try to find it in the config file # next try to find it in the config file
...@@ -77,7 +84,7 @@ def fetch_val_for_key(key): ...@@ -77,7 +84,7 @@ def fetch_val_for_key(key):
return theano_cfg.get(section, option) return theano_cfg.get(section, option)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
raise KeyError(key) raise KeyError(key)
class TheanoConfigParser(object): class TheanoConfigParser(object):
#properties are installed by AddConfigVar #properties are installed by AddConfigVar
...@@ -143,7 +150,7 @@ class ConfigParam(object): ...@@ -143,7 +150,7 @@ class ConfigParam(object):
self.val = val self.val = val
deleter=None deleter=None
class EnumStr(ConfigParam): class EnumStr(ConfigParam):
def __init__(self, default, *options): def __init__(self, default, *options):
self.default = default self.default = default
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论