提交 598991d7 authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5412 from notoraptor/fix-theano-scripts-on-windows

Fix theano scripts on windows
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function import theano_cache
import logging theano_cache.main()
import os
import sys
import theano
from theano import config
import theano.gof.compiledir
from theano.gof.cc import get_module_cache
_logger = logging.getLogger('theano.bin.theano-cache')
def print_help(exit_status):
if exit_status:
print('command "%s" not recognized' % (' '.join(sys.argv)))
print('Type "theano-cache" to print the cache location')
print('Type "theano-cache help" to print this help')
print('Type "theano-cache clear" to erase the cache')
print('Type "theano-cache list" to print the cache content')
print('Type "theano-cache unlock" to unlock the cache directory')
print('Type "theano-cache cleanup" to delete keys in the old '
'format/code version')
print('Type "theano-cache purge" to force deletion of the cache directory')
print('Type "theano-cache basecompiledir" '
'to print the parent of the cache directory')
print('Type "theano-cache basecompiledir list" '
'to print the content of the base compile dir')
print('Type "theano-cache basecompiledir purge" '
'to remove everything in the base compile dir, '
'that is, erase ALL cache directories')
sys.exit(exit_status)
if len(sys.argv) == 1:
print(config.compiledir)
elif len(sys.argv) == 2:
if sys.argv[1] == 'help':
print_help(exit_status=0)
if sys.argv[1] == 'clear':
# We skip the refresh on module cache creation because the refresh will
# be done when calling clear afterwards.
cache = get_module_cache(init_args=dict(do_refresh=False))
cache.clear(unversioned_min_age=-1, clear_base_files=True,
delete_if_problem=True)
# Print a warning if some cached modules were not removed, so that the
# user knows he should manually delete them, or call
# theano-cache purge, # to properly clear the cache.
items = [item for item in sorted(os.listdir(cache.dirname))
if item.startswith('tmp')]
if items:
_logger.warning(
'There remain elements in the cache dir that you may '
'need to erase manually. The cache dir is:\n %s\n'
'You can also call "theano-cache purge" to '
'remove everything from that directory.' %
config.compiledir)
_logger.debug('Remaining elements (%s): %s' %
(len(items), ', '.join(items)))
elif sys.argv[1] == 'list':
theano.gof.compiledir.print_compiledir_content()
elif sys.argv[1] == 'cleanup':
theano.gof.compiledir.cleanup()
cache = get_module_cache(init_args=dict(do_refresh=False))
cache.clear_old()
elif sys.argv[1] == 'unlock':
theano.gof.compilelock.force_unlock()
print('Lock successfully removed!')
elif sys.argv[1] == 'purge':
theano.gof.compiledir.compiledir_purge()
elif sys.argv[1] == 'basecompiledir':
# Simply print the base_compiledir
print(theano.config.base_compiledir)
else:
print_help(exit_status=1)
elif len(sys.argv) == 3 and sys.argv[1] == 'basecompiledir':
if sys.argv[2] == 'list':
theano.gof.compiledir.basecompiledir_ls()
elif sys.argv[2] == 'purge':
theano.gof.compiledir.basecompiledir_purge()
else:
print_help(exit_status=1)
else:
print_help(exit_status=1)
差异被折叠。
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- import theano_test
"""IPython Test Suite Runner. theano_test.main()
"""
from __future__ import print_function
# The tests can't even run if nose isn't available, so might as well give the
# user a civilized error message in that case.
try:
import nose
except ImportError:
error = """\
ERROR: The IPython test suite requires nose to run.
Please install nose on your system first and try again.
For information on installing nose, see:
http://nose.readthedocs.org/en/latest/
Exiting."""
import sys
print(error, file=sys.stderr)
else:
import theano
theano.test()
#!/usr/bin/env python
from __future__ import print_function
import logging
import os
import sys
if sys.platform == 'win32':
config_cxx = 'cxx='
theano_flags = os.environ['THEANO_FLAGS'] if 'THEANO_FLAGS' in os.environ else ''
if theano_flags:
theano_flags += ','
theano_flags += config_cxx
os.environ['THEANO_FLAGS'] = theano_flags
import theano
from theano import config
import theano.gof.compiledir
from theano.gof.cc import get_module_cache
_logger = logging.getLogger('theano.bin.theano-cache')
def print_help(exit_status):
if exit_status:
print('command "%s" not recognized' % (' '.join(sys.argv)))
print('Type "theano-cache" to print the cache location')
print('Type "theano-cache help" to print this help')
print('Type "theano-cache clear" to erase the cache')
print('Type "theano-cache list" to print the cache content')
print('Type "theano-cache unlock" to unlock the cache directory')
print('Type "theano-cache cleanup" to delete keys in the old '
'format/code version')
print('Type "theano-cache purge" to force deletion of the cache directory')
print('Type "theano-cache basecompiledir" '
'to print the parent of the cache directory')
print('Type "theano-cache basecompiledir list" '
'to print the content of the base compile dir')
print('Type "theano-cache basecompiledir purge" '
'to remove everything in the base compile dir, '
'that is, erase ALL cache directories')
sys.exit(exit_status)
def main():
if len(sys.argv) == 1:
print(config.compiledir)
elif len(sys.argv) == 2:
if sys.argv[1] == 'help':
print_help(exit_status=0)
if sys.argv[1] == 'clear':
# We skip the refresh on module cache creation because the refresh will
# be done when calling clear afterwards.
cache = get_module_cache(init_args=dict(do_refresh=False))
cache.clear(unversioned_min_age=-1, clear_base_files=True,
delete_if_problem=True)
# Print a warning if some cached modules were not removed, so that the
# user knows he should manually delete them, or call
# theano-cache purge, # to properly clear the cache.
items = [item for item in sorted(os.listdir(cache.dirname))
if item.startswith('tmp')]
if items:
_logger.warning(
'There remain elements in the cache dir that you may '
'need to erase manually. The cache dir is:\n %s\n'
'You can also call "theano-cache purge" to '
'remove everything from that directory.' %
config.compiledir)
_logger.debug('Remaining elements (%s): %s' %
(len(items), ', '.join(items)))
elif sys.argv[1] == 'list':
theano.gof.compiledir.print_compiledir_content()
elif sys.argv[1] == 'cleanup':
theano.gof.compiledir.cleanup()
cache = get_module_cache(init_args=dict(do_refresh=False))
cache.clear_old()
elif sys.argv[1] == 'unlock':
theano.gof.compilelock.force_unlock()
print('Lock successfully removed!')
elif sys.argv[1] == 'purge':
theano.gof.compiledir.compiledir_purge()
elif sys.argv[1] == 'basecompiledir':
# Simply print the base_compiledir
print(theano.config.base_compiledir)
else:
print_help(exit_status=1)
elif len(sys.argv) == 3 and sys.argv[1] == 'basecompiledir':
if sys.argv[2] == 'list':
theano.gof.compiledir.basecompiledir_ls()
elif sys.argv[2] == 'purge':
theano.gof.compiledir.basecompiledir_purge()
else:
print_help(exit_status=1)
else:
print_help(exit_status=1)
if __name__ == '__main__':
main()
差异被折叠。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""IPython Test Suite Runner.
"""
from __future__ import print_function
def main():
# The tests can't even run if nose isn't available, so might as well give the
# user a civilized error message in that case.
try:
import nose
except ImportError:
error = """\
ERROR: The IPython test suite requires nose to run.
Please install nose on your system first and try again.
For information on installing nose, see:
http://nose.readthedocs.org/en/latest/
Exiting."""
import sys
print(error, file=sys.stderr)
else:
import theano
theano.test()
if __name__ == "__main__":
main()
...@@ -173,7 +173,11 @@ def do_setup(): ...@@ -173,7 +173,11 @@ def do_setup():
'theano.misc': ['*.sh'], 'theano.misc': ['*.sh'],
'theano.d3viz' : ['html/*','css/*','js/*'] 'theano.d3viz' : ['html/*','css/*','js/*']
}, },
scripts=['bin/theano-cache', 'bin/theano-nose', 'bin/theano-test'], entry_points={
'console_scripts': ['theano-cache = bin.theano_cache:main',
'theano-nose = bin.theano_nose:main',
'theano-test = bin.theano_test:main']
},
keywords=' '.join([ keywords=' '.join([
'theano', 'math', 'numerical', 'symbolic', 'blas', 'theano', 'math', 'numerical', 'symbolic', 'blas',
'numpy', 'gpu', 'autodiff', 'differentiation' 'numpy', 'gpu', 'autodiff', 'differentiation'
......
...@@ -488,10 +488,8 @@ else: ...@@ -488,10 +488,8 @@ else:
"Default linker used if the theano flags mode is Mode", "Default linker used if the theano flags mode is Mode",
EnumStr('vm', 'py', 'vm_nogc'), EnumStr('vm', 'py', 'vm_nogc'),
in_c_key=False) in_c_key=False)
try: if type(config).cxx.is_default:
# If the user provided an empty value for cxx, do not warn. # If the user provided an empty value for cxx, do not warn.
theano.configparser.fetch_val_for_key('cxx')
except KeyError:
_logger.warning( _logger.warning(
'g++ not detected ! Theano will be unable to execute ' 'g++ not detected ! Theano will be unable to execute '
'optimized C-implementations (for both CPU and GPU) and will ' 'optimized C-implementations (for both CPU and GPU) and will '
......
...@@ -656,6 +656,10 @@ class Stack(VM): ...@@ -656,6 +656,10 @@ class Stack(VM):
try: try:
# If cxx is explicitely set to an empty string, we do not want to import neither lazylinker C code
# nor lazylinker compiled C code from cache.
if not theano.config.cxx:
raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
from . import lazylinker_c from . import lazylinker_c
class CVM(lazylinker_c.CLazyLinker, VM): class CVM(lazylinker_c.CLazyLinker, VM):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论