#16242: assert_have_dot2tex should reraise exception not replace it
-------------------------------------+-------------------------------------
       Reporter:  slabbe             |        Owner:  slabbe
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.2
      Component:  packages:          |   Resolution:
  optional                           |    Merged in:
       Keywords:                     |    Reviewers:
        Authors:  Sébastien Labbé    |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:  u/slabbe/16242     |  ecc5f70423cf25c566fd8f30364a3ffe295d6ad8
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Description changed by slabbe:

Old description:

> I installed {{{sage -i dot2tex}}} and then, the method
> {{{assert_have_dot2tex}}} says that {{{dot2tex not available}}}.
>
> The reason is that the function {{{assert_have_dot2tex}}} replaces the
> {{{ImportError}}} (in my case a pyparsing importerror) by a
> {{{RuntimeError}}} with the {{{dot2tex not available}}} message. This
> hides the real error.
>
> BEFORE fix:
>
> {{{
> sage: from sage.graphs.dot2tex_utils import assert_have_dot2tex
> sage: assert_have_dot2tex()
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call
> last)
> <ipython-input-2-9f40acb4631c> in <module>()
> ----> 1 assert_have_dot2tex()
>
> /Users/slabbe/Applications/sage-review/local/lib/python2.7/site-
> packages/sage/graphs/dot2tex_utils.pyc in assert_have_dot2tex()
>      60             raise RuntimeError(check_error_string)
>      61     except ImportError:
> ---> 62         raise RuntimeError(missing_error_string)
>      63
>      64 def quoted_latex(x):
>
> RuntimeError:
> dot2tex not available.
>
> Please see :meth:`sage.graphs.generic_graph.GenericGraph.layout_graphviz`
> for installation instructions.
>
> }}}
>
> AFTER fix:
>
> {{{
> sage: from sage.graphs.dot2tex_utils import assert_have_dot2tex
> sage: assert_have_dot2tex()
>
> An error occured when importing dot2tex.
>
> Please see :meth:`sage.graphs.generic_graph.GenericGraph.layout_graphviz`
> for installation instructions.
>
> ---------------------------------------------------------------------------
> ImportError                               Traceback (most recent call
> last)
> <ipython-input-2-9f40acb4631c> in <module>()
> ----> 1 assert_have_dot2tex()
>
> /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
> packages/sage/graphs/dot2tex_utils.pyc in assert_have_dot2tex()
>      56 """
>      57     try:
> ---> 58         import dot2tex
>      59     except ImportError as e:
>      60         print import_error_string
>
> /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
> packages/dot2tex/__init__.py in <module>()
>      34
>      35
> ---> 36 import dot2tex as d2t
>      37
>      38 def get_logstream():
>
> /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
> packages/dot2tex/dot2tex.py in <module>()
>      45 import warnings
>      46
> ---> 47 import dotparsing
>      48
>      49 # Silence DeprecationWarnings about os.popen3 in Python 2.6
>
> /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
> packages/dot2tex/dotparsing.py in <module>()
>      24     import matplotlib.pyparsing_py2 as pyparsing
>      25 except ImportError:
> ---> 26     import matplotlib.pyparsing as pyparsing
>      27     # just raise if that failed, too
>      28
>
> ImportError: No module named pyparsing
>
> }}}

New description:

 I installed {{{sage -i dot2tex}}} and then I get an error saying that
 {{{dot2tex not available}}}:

 {{{
 sage: G = DiGraph()
 sage: G.add_edge(3333, 88, 'my_label')
 sage: G.set_latex_options(format='dot2tex')
 sage: view(G)
 Traceback (most recent call last):
 ...
 RuntimeError: dot2tex not available.
 }}}

 The reason is that the function {{{assert_have_dot2tex}}} replaces the
 {{{ImportError}}} (in my case a pyparsing importerror) by a
 {{{RuntimeError}}} with the {{{dot2tex not available}}} message. This
 hides the real error.

 BEFORE fix:

 {{{
 sage: from sage.graphs.dot2tex_utils import assert_have_dot2tex
 sage: assert_have_dot2tex()
 ---------------------------------------------------------------------------
 RuntimeError                              Traceback (most recent call
 last)
 <ipython-input-2-9f40acb4631c> in <module>()
 ----> 1 assert_have_dot2tex()

 /Users/slabbe/Applications/sage-review/local/lib/python2.7/site-
 packages/sage/graphs/dot2tex_utils.pyc in assert_have_dot2tex()
      60             raise RuntimeError(check_error_string)
      61     except ImportError:
 ---> 62         raise RuntimeError(missing_error_string)
      63
      64 def quoted_latex(x):

 RuntimeError:
 dot2tex not available.

 Please see :meth:`sage.graphs.generic_graph.GenericGraph.layout_graphviz`
 for installation instructions.

 }}}

 AFTER fix:

 {{{
 sage: from sage.graphs.dot2tex_utils import assert_have_dot2tex
 sage: assert_have_dot2tex()

 An error occured when importing dot2tex.

 Please see :meth:`sage.graphs.generic_graph.GenericGraph.layout_graphviz`
 for installation instructions.

 ---------------------------------------------------------------------------
 ImportError                               Traceback (most recent call
 last)
 <ipython-input-2-9f40acb4631c> in <module>()
 ----> 1 assert_have_dot2tex()

 /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
 packages/sage/graphs/dot2tex_utils.pyc in assert_have_dot2tex()
      56 """
      57     try:
 ---> 58         import dot2tex
      59     except ImportError as e:
      60         print import_error_string

 /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
 packages/dot2tex/__init__.py in <module>()
      34
      35
 ---> 36 import dot2tex as d2t
      37
      38 def get_logstream():

 /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
 packages/dot2tex/dot2tex.py in <module>()
      45 import warnings
      46
 ---> 47 import dotparsing
      48
      49 # Silence DeprecationWarnings about os.popen3 in Python 2.6

 /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-
 packages/dot2tex/dotparsing.py in <module>()
      24     import matplotlib.pyparsing_py2 as pyparsing
      25 except ImportError:
 ---> 26     import matplotlib.pyparsing as pyparsing
      27     # just raise if that failed, too
      28

 ImportError: No module named pyparsing

 }}}

--

--
Ticket URL: <http://trac.sagemath.org/ticket/16242#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to