提交 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
.. note::
Compiled libraries are stored within a specific compilation directory,
which by default is set to ``$HOME/.theano/compiledir_xxx``, where
``xxx`` identifies the platform. It may be manually set to a different
location either by setting :attr:`config.compiledir` or
``xxx`` identifies the platform (under Windows the default location
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
using one of the configuration mechanisms described in :mod:`config`.
......
......@@ -273,15 +273,10 @@ import theano and print the config variable, as in:
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
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.
......@@ -289,7 +284,7 @@ import theano and print the config variable, as in:
.. attribute:: compiledir
Default: $HOME/.theano/<arch-identifier>
Default: ``config.base_compiledir``/<arch-identifier>
This directory stores dynamically-compiled modules for a particular
architecture.
......
import os
import subprocess
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')
......@@ -118,29 +122,38 @@ AddConfigVar('on_opt_error',
EnumStr('warn', 'raise'),
in_c_key=False)
def get_home_dir():
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
def safe_no_home(home):
"""
Make sure the user is not attempting to use `config.home`.
This config option was removed in Thenao 0.5 since it was redundant with
`config.base_compiledir`. This filter function ensures people who were
setting the location of their compilation directory through `config.home`
switch to `config.basecompiledir` instead, by raising an error when
`config.home` is used.
"""
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',
"User home directory",
StrParam(get_home_dir()),
"This config option was removed in 0.5: do not use it!",
ConfigParam('', allow_override=False, filter=safe_no_home),
in_c_key=False)
AddConfigVar('nocleanup',
"Suppress the deletion of code files that did not compile cleanly",
BoolParam(False),
in_c_key=False)
# This flag is used when we import Theano to initialize 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
......
import cPickle
import errno
import os
......@@ -51,19 +50,36 @@ def filter_compiledir(path):
return path
# TODO Using the local user profile on Windows is currently disabled as it
# is not documented yet, and may break some existing code. It will be enabled
# in a future code update.
if False and sys.platform == 'win32':
# On Windows we should not write 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.
basecompiledir = os.path.join(os.environ['LOCALAPPDATA'], 'theano')
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:
basecompiledir = os.path.join(config.home, '.theano')
default_base_compiledir = os.path.join(get_home_dir(), '.theano')
AddConfigVar('base_compiledir',
"arch-independent cache directory for compiled modules",
StrParam(basecompiledir, allow_override=False))
StrParam(default_base_compiledir, allow_override=False))
AddConfigVar('compiledir',
"arch-dependent cache directory for compiled modules",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论