提交 0f446def authored 作者: notoraptor's avatar notoraptor

Use the entry_points/console_scripts feature of setup.py

to make theano scripts installed when running pip install. These step are done to fix issue #5308. The bin folder containing the scripts is now importable from Python, with each script embedding its code into a main() function specified as the entry point of the script in `setup.py`. We also detect a Windows-specific error: the cache folder cannot be deleted because it contains shared libraries that are always loaded at theano importation and stay opened on Windows, which forbide the deletion of the shared library files in the cache. The workaround chosen is to unset theano config flag `cxx` only on Windows platform and only in theano-cache script. Doing that, Theano will not try to compile any C code, and will also not try to load compiled C codes that are in the cache, allowing these files to be deleted. To ensure this workaround does work, we also ensure that lazylinker module will be also ignored from cache when `cxx` is unset. Previously, if cxx was unset, Theano would not compile lazylinker but would look for an already compiled version of this module in the cache.
上级 fcdd8c77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""IPython Test Suite Runner.
"""
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()
......@@ -4,6 +4,14 @@ 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
......@@ -32,9 +40,11 @@ def print_help(exit_status):
'that is, erase ALL cache directories')
sys.exit(exit_status)
if len(sys.argv) == 1:
def main():
if len(sys.argv) == 1:
print(config.compiledir)
elif len(sys.argv) == 2:
elif len(sys.argv) == 2:
if sys.argv[1] == 'help':
print_help(exit_status=0)
if sys.argv[1] == 'clear':
......@@ -74,12 +84,16 @@ elif len(sys.argv) == 2:
print(theano.config.base_compiledir)
else:
print_help(exit_status=1)
elif len(sys.argv) == 3 and sys.argv[1] == 'basecompiledir':
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:
else:
print_help(exit_status=1)
if __name__ == '__main__':
main()
......@@ -25,7 +25,7 @@ import textwrap
import sys
from nose.plugins import Plugin
def main():
def main_function():
# Handle the --theano arguments
if "--theano" in sys.argv:
i = sys.argv.index("--theano")
......@@ -200,6 +200,14 @@ def help():
print(textwrap.dedent(help_msg))
def main(args=None):
if '--help' in sys.argv or '-h' in sys.argv:
help()
else:
result = main_function()
sys.exit(result)
class DisabDocString(Plugin):
"""
......@@ -258,8 +266,4 @@ class DisabDocString(Plugin):
return False
if __name__ == '__main__':
if '--help' in sys.argv or '-h' in sys.argv:
help()
else:
result = main()
sys.exit(result)
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():
'theano.misc': ['*.sh'],
'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([
'theano', 'math', 'numerical', 'symbolic', 'blas',
'numpy', 'gpu', 'autodiff', 'differentiation'
......
......@@ -656,6 +656,8 @@ class Stack(VM):
try:
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
class CVM(lazylinker_c.CLazyLinker, VM):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论