提交 73575d81 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Removed the config.home option

This option was redundant with config.base_compiledir
上级 1efddab2
...@@ -273,23 +273,10 @@ import theano and print the config variable, as in: ...@@ -273,23 +273,10 @@ import theano and print the config variable, as in:
This flag's value cannot be modified during the program execution. This flag's value cannot be modified during the program execution.
.. attribute:: home
Default: On Linux: $HOME/.theano. On Windows: $LOCALAPPDATA\\Theano
This is the base directory where all Theano files are stored. Currently,
the only files being stored are compiled C modules, and thus changing ``home``
is similar to changing ``base_compiledir`` (described below).
Note however that ``home`` used to have a different meaning in previous
versions of Theano (up to 0.4.1), and to make sure its new meaning is
understood, it is currently forbidden to change ``home`` without also
changing either ``base_compiledir`` or ``compiledir``.
This flag's value cannot be modified during the program execution.
.. attribute:: base_compiledir .. attribute:: base_compiledir
Default: ``config.home`` Default: On Windows: $LOCALAPPDATA\\Theano if $LOCALAPPDATA is defined,
otherwise and on other systems: ~/.theano.
This directory stores the architecture-dependent compilation directories. This directory stores the architecture-dependent compilation directories.
......
...@@ -3,7 +3,10 @@ import logging ...@@ -3,7 +3,10 @@ import logging
import subprocess import subprocess
import sys import sys
from theano.configparser import TheanoConfigParser, AddConfigVar, EnumStr, StrParam, IntParam, FloatParam, BoolParam from theano.configparser import (
AddConfigVar, BoolParam, ConfigParam, EnumStr, IntParam, FloatParam,
StrParam, TheanoConfigParser)
_logger = logging.getLogger('theano.configdefaults') _logger = logging.getLogger('theano.configdefaults')
...@@ -119,37 +122,38 @@ AddConfigVar('on_opt_error', ...@@ -119,37 +122,38 @@ AddConfigVar('on_opt_error',
EnumStr('warn', 'raise'), EnumStr('warn', 'raise'),
in_c_key=False) in_c_key=False)
def get_home_dir():
home = os.getenv('HOME') def safe_no_home(home):
if home is None: """
# This expanduser usually works on Windows (see discussion on Make sure the user is not attempting to use `config.home`.
# theano-users, July 13 2010).
home = os.path.expanduser('~') This config option was removed in Thenao 0.5 since it was redundant with
if home == '~': `config.base_compiledir`. This filter function ensures people who were
# This might happen when expanduser fails. Although the cause of setting the location of their compilation directory through `config.home`
# failure is a mystery, it has been seen on some Windows system. switch to `config.basecompiledir` instead, by raising an error when
home = os.getenv('USERPROFILE') `config.home` is used.
assert home is not None """
return home if home:
raise RuntimeError(
# On Windows we should avoid writing temporary files to a directory that is 'The `config.home` option has been removed and should not be '
# part of the roaming part of the user profile. Instead we use the local part 'used anymore. Please set the `config.base_compiledir` option '
# of the user profile, when available. 'instead (for instance to: %s)' %
if sys.platform == 'win32' and os.getenv('LOCALAPPDATA') is not None: os.path.join(home, '.theano'))
default_home = os.path.join(os.getenv('LOCALAPPDATA'), 'Theano') return True
else:
default_home = os.path.join(get_home_dir(), '.theano')
AddConfigVar('home', AddConfigVar('home',
"Home directory for Theano files", "This config option was removed in 0.5: do not use it!",
StrParam(default_home, allow_override=False), ConfigParam('', allow_override=False, filter=safe_no_home),
in_c_key=False) in_c_key=False)
AddConfigVar('nocleanup', AddConfigVar('nocleanup',
"Suppress the deletion of code files that did not compile cleanly", "Suppress the deletion of code files that did not compile cleanly",
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
# This flag is used when we import Theano to initialize global variables. # This flag is used when we import Theano to initialize global variables.
# So changing it after import will not modify these global variables. # So changing it after import will not modify these global variables.
# This could be done differently... but for now we simply prevent it from being # This could be done differently... but for now we simply prevent it from being
......
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
import platform import platform
import re import re
import sys import sys
import warnings
import theano import theano
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam from theano.configparser import config, AddConfigVar, ConfigParam, StrParam
...@@ -51,47 +50,47 @@ def filter_compiledir(path): ...@@ -51,47 +50,47 @@ def filter_compiledir(path):
return path return path
def get_home_dir():
"""
Return location of the user's home directory.
"""
home = os.getenv('HOME')
if home is None:
# This expanduser usually works on Windows (see discussion on
# theano-users, July 13 2010).
home = os.path.expanduser('~')
if home == '~':
# This might happen when expanduser fails. Although the cause of
# failure is a mystery, it has been seen on some Windows system.
home = os.getenv('USERPROFILE')
assert home is not None
return home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if sys.platform == 'win32' and os.getenv('LOCALAPPDATA') is not None:
default_base_compiledir = os.path.join(os.getenv('LOCALAPPDATA'), 'Theano')
else:
default_base_compiledir = os.path.join(get_home_dir(), '.theano')
AddConfigVar('base_compiledir', AddConfigVar('base_compiledir',
"arch-independent cache directory for compiled modules", "arch-independent cache directory for compiled modules",
StrParam(config.home, allow_override=False)) StrParam(default_base_compiledir, allow_override=False))
default_compiledir = os.path.join(
os.path.expanduser(config.base_compiledir),
default_compiledirname())
AddConfigVar('compiledir', AddConfigVar('compiledir',
"arch-dependent cache directory for compiled modules", "arch-dependent cache directory for compiled modules",
ConfigParam(default_compiledir, ConfigParam(
os.path.join(
os.path.expanduser(config.base_compiledir),
default_compiledirname()),
filter=filter_compiledir, filter=filter_compiledir,
allow_override=False)) allow_override=False))
# The role of `config.home` was changed compared to Theano 0.4.1. It used to
# be the location of the user home directory. Now, it directly points to the
# directory where Theano should save its own data files. Typically, the
# difference is that it now includes the '.theano' folder, while it used to be
# the parent of that folder. In order for this change to be safe, we currently
# prevent people from changing `config.home` unless they also change
# the compilation directory.
if (config.home != theano.configdefaults.default_home and
config.base_compiledir == config.home and
# We need to compare to the `real` path because this is what is used in
# `filter_compiledir`.
config.compiledir == os.path.realpath(default_compiledir)):
# The user changed `config.home` but is still using the default values for
# `config.base_compiledir` and `config.compiledir`.
raise RuntimeError(
'You manually set your Theano home directory (to %s), but kept '
'the default compilation directory. Please note that the meaning '
'of the `home` directory was changed: it is now the base '
'directory for all Theano files, instead of being its parent '
'directory. To get rid of this error, please set the '
'`base_compiledir` config option to the directory you want '
'compiled files to be stored into (for instance: %s).' % (
config.home,
os.path.join(config.home, '.theano')))
def print_compiledir_content(): def print_compiledir_content():
def flatten(a): def flatten(a):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论