提交 c08a6f31 authored 作者: nouiz's avatar nouiz

Merge pull request #246 from delallea/win_home

Changed default compiledir under Windows
...@@ -100,8 +100,9 @@ case if ``borrow`` was True, the thunk would be allowed to reuse (or ...@@ -100,8 +100,9 @@ case if ``borrow`` was True, the thunk would be allowed to reuse (or
.. note:: .. note::
Compiled libraries are stored within a specific compilation directory, Compiled libraries are stored within a specific compilation directory,
which by default is set to ``$HOME/.theano/compiledir_xxx``, where which by default is set to ``$HOME/.theano/compiledir_xxx``, where
``xxx`` identifies the platform. It may be manually set to a different ``xxx`` identifies the platform (under Windows the default location
location either by setting :attr:`config.compiledir` or is instead ``$LOCALAPPDATA\Theano\compiledir_xxx``). It may be manually set
to a different location either by setting :attr:`config.compiledir` or
:attr:`config.base_compiledir`, either within your Python script or by :attr:`config.base_compiledir`, either within your Python script or by
using one of the configuration mechanisms described in :mod:`config`. using one of the configuration mechanisms described in :mod:`config`.
......
...@@ -273,15 +273,10 @@ import theano and print the config variable, as in: ...@@ -273,15 +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: env-variable $HOME
This is used to compute the compiledir and base_compiledir attributes
.. attribute:: base_compiledir .. attribute:: base_compiledir
Default: $HOME/.theano 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.
...@@ -289,7 +284,7 @@ import theano and print the config variable, as in: ...@@ -289,7 +284,7 @@ import theano and print the config variable, as in:
.. attribute:: compiledir .. attribute:: compiledir
Default: $HOME/.theano/<arch-identifier> Default: ``config.base_compiledir``/<arch-identifier>
This directory stores dynamically-compiled modules for a particular This directory stores dynamically-compiled modules for a particular
architecture. architecture.
......
import os import os
import subprocess
import logging import logging
import subprocess
import sys
from theano.configparser import (
AddConfigVar, BoolParam, ConfigParam, EnumStr, IntParam, FloatParam,
StrParam, TheanoConfigParser)
from theano.configparser import TheanoConfigParser, AddConfigVar, EnumStr, StrParam, IntParam, FloatParam, BoolParam
_logger = logging.getLogger('theano.configdefaults') _logger = logging.getLogger('theano.configdefaults')
...@@ -118,29 +122,38 @@ AddConfigVar('on_opt_error', ...@@ -118,29 +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(
'The `config.home` option has been removed and should not be '
'used anymore. Please set the `config.base_compiledir` option '
'instead (for instance to: %s)' %
os.path.join(home, '.theano'))
return True
AddConfigVar('home', AddConfigVar('home',
"User home directory", "This config option was removed in 0.5: do not use it!",
StrParam(get_home_dir()), 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
......
import cPickle import cPickle
import errno import errno
import os import os
...@@ -51,19 +50,36 @@ def filter_compiledir(path): ...@@ -51,19 +50,36 @@ def filter_compiledir(path):
return path return path
# TODO Using the local user profile on Windows is currently disabled as it def get_home_dir():
# is not documented yet, and may break some existing code. It will be enabled """
# in a future code update. Return location of the user's home directory.
if False and sys.platform == 'win32': """
# On Windows we should not write temporary files to a directory home = os.getenv('HOME')
# that is part of the roaming part of the user profile. Instead if home is None:
# we use the local part of the user profile. # This expanduser usually works on Windows (see discussion on
basecompiledir = os.path.join(os.environ['LOCALAPPDATA'], 'theano') # 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: else:
basecompiledir = os.path.join(config.home, '.theano') 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(basecompiledir, allow_override=False)) StrParam(default_base_compiledir, allow_override=False))
AddConfigVar('compiledir', AddConfigVar('compiledir',
"arch-dependent cache directory for compiled modules", "arch-dependent cache directory for compiled modules",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论