提交 863677d0 authored 作者: Frederic's avatar Frederic

Move how pydot is imported and detected to respect pep8.

上级 7266073f
...@@ -7,6 +7,12 @@ import sys, os, StringIO ...@@ -7,6 +7,12 @@ import sys, os, StringIO
import numpy import numpy
try:
import pydot as pd
pydot_imported = True
except ImportError:
pydot_imported = False
import theano import theano
import gof import gof
from theano import config from theano import config
...@@ -463,11 +469,9 @@ def pydotprint(fct, outfile=None, ...@@ -463,11 +469,9 @@ def pydotprint(fct, outfile=None,
raise ValueError(('pydotprint expects as input a theano.function or ' raise ValueError(('pydotprint expects as input a theano.function or '
'the env of a function!'), fct) 'the env of a function!'), fct)
try: if not pydot_imported:
import pydot as pd raise RuntimeError ("Failed to import pydot. You must install pydot"
except ImportError: " for `pydotprint` to work.")
print ("Failed to import pydot. You must install pydot for "
"`pydotprint` to work.")
return return
g=pd.Dot() g=pd.Dot()
......
...@@ -22,9 +22,7 @@ def test_pydotprint_cond_highlight(): ...@@ -22,9 +22,7 @@ def test_pydotprint_cond_highlight():
""" """
# Skip test if pydot is not available. # Skip test if pydot is not available.
try: if not theano.printing.pydot_imported:
import pydot
except ImportError:
raise SkipTest('pydot not available') raise SkipTest('pydot not available')
x = tensor.dvector() x = tensor.dvector()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论