Hi all,

in various places I've been using the mpl sphinxext tools, so I
figured I'd best send you a few small updates I've made to them before
they bitrot too much.  Most of the changes are just cleanup and
documentation, though there is a functional fix in
inheritance_diagram, which was just not working for us in nipy.
There's a comment indicating the change,  I hope it makes sense.

I made the patch against svn trunk, though I can't quite test because
I'm getting this:

maqroll[doc]> ./make.py html
Traceback (most recent call last):
  File "./make.py", line 98, in <module>
    func()
  File "./make.py", line 31, in html
    shutil.copy('../lib/matplotlib/mpl-data/matplotlibrc',
'_static/matplotlibrc')
  File "/usr/lib/python2.5/shutil.py", line 85, in copy
    copyfile(src, dst)
  File "/usr/lib/python2.5/shutil.py", line 51, in copyfile
    fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory:
'../lib/matplotlib/mpl-data/matplotlibrc'


I'm a bit surprised to see this problem, since I imagine you guys
build frequently.  But my svn is indeed up to date and that file is
just not there.  I'm not sure which way you want the fix to go, so
I'll leave that decision to you guys.

Cheers,

f
Index: inheritance_diagram.py
===================================================================
--- inheritance_diagram.py	(revision 6861)
+++ inheritance_diagram.py	(working copy)
@@ -42,6 +42,17 @@
 from docutils.parsers.rst import directives
 from sphinx.roles import xfileref_role
 
+def my_import(name):
+    """Module importer - taken from the python documentation.
+
+    This function allows importing names with dots in them."""
+    
+    mod = __import__(name)
+    components = name.split('.')
+    for comp in components[1:]:
+        mod = getattr(mod, comp)
+    return mod
+
 class DotException(Exception):
     pass
 
@@ -84,6 +95,13 @@
             path = base
         try:
             module = __import__(path, None, None, [])
+            # We must do an import of the fully qualified name.  Otherwise if a
+            # subpackage 'a.b' is requested where 'import a' does NOT provide
+            # 'a.b' automatically, then 'a.b' will not be found below.  This
+            # second call will force the equivalent of 'import a.b' to happen
+            # after the top-level import above.
+            my_import(fullname)
+            
         except ImportError:
             raise ValueError(
                 "Could not import class or module '%s' specified for inheritance diagram" % name)
Index: ipython_console_highlighting.py
===================================================================
--- ipython_console_highlighting.py	(revision 6861)
+++ ipython_console_highlighting.py	(working copy)
@@ -1,18 +1,32 @@
+"""reST directive for syntax-highlighting ipython interactive sessions.
+"""
+
+#-----------------------------------------------------------------------------
+# Needed modules
+
+# Standard library
+import re
+
+# Third party
 from pygments.lexer import Lexer, do_insertions
-from pygments.lexers.agile import PythonConsoleLexer, PythonLexer, \
-    PythonTracebackLexer
+from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer, 
+                                   PythonTracebackLexer)
 from pygments.token import Comment, Generic
+
 from sphinx import highlighting
-import re
 
+
+#-----------------------------------------------------------------------------
+# Global constants
 line_re = re.compile('.*?\n')
 
+#-----------------------------------------------------------------------------
+# Code begins - classes and functions
+
 class IPythonConsoleLexer(Lexer):
     """
     For IPython console output or doctests, such as:
 
-    Tracebacks are not currently supported.
-
     .. sourcecode:: ipython
 
       In [1]: a = 'foo'
@@ -24,7 +38,14 @@
       foo
 
       In [4]: 1 / 0
+
+    Notes:
+
+      - Tracebacks are not currently supported.
+
+      - It assumes the default IPython prompts, not customized ones.
     """
+    
     name = 'IPython console session'
     aliases = ['ipython']
     mimetypes = ['text/x-ipython-console']
@@ -72,4 +93,6 @@
                                       pylexer.get_tokens_unprocessed(curcode)):
                 yield item
 
+#-----------------------------------------------------------------------------
+# Register the extension as a valid pygments lexer
 highlighting.lexers['ipython'] = IPythonConsoleLexer()
Index: mathmpl.py
===================================================================
--- mathmpl.py	(revision 6861)
+++ mathmpl.py	(working copy)
@@ -1,3 +1,25 @@
+"""matplotlib-based directive for math rendering in reST using sphinx.
+
+To use this extension, add ``mathmpl`` to the list of extensions in
+:file:`conf.py`.
+
+Note:
+
+Current SVN versions of Sphinx now include built-in support for math.
+There are two flavors:
+
+  - pngmath: uses dvipng to render the equation
+
+  - jsmath: renders the math in the browser using Javascript
+
+To use these extensions instead of the code in this module, add
+``sphinx.ext.pngmath`` or ``sphinx.ext.jsmath`` to the list of extensions in
+:file:`conf.py` instead of ``mathmpl``.
+
+All three of these options for math are designed to behave in the same
+way.
+"""
+
 import os
 import sys
 try:
Index: only_directives.py
===================================================================
--- only_directives.py	(revision 6861)
+++ only_directives.py	(working copy)
@@ -1,11 +1,15 @@
-#
-# A pair of directives for inserting content that will only appear in
-# either html or latex.
-#
+"""Sphinx directives for selective inclusion of contents.
 
+A pair of directives for inserting content that will only appear in
+either html or latex.
+"""
+
+# Required modules
 from docutils.nodes import Body, Element
 from docutils.parsers.rst import directives
 
+
+# Code begins
 class only_base(Body, Element):
     def dont_traverse(self, *args, **kwargs):
         return []
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to