Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c4b297

Browse files
committed
addplied Fernando's sphinxext patch
svn path=/trunk/matplotlib/; revision=6863
1 parent 5291d63 commit 8c4b297

4 files changed

Lines changed: 76 additions & 9 deletions

File tree

doc/sphinxext/inheritance_diagram.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ class E(B): pass
4242
from docutils.parsers.rst import directives
4343
from sphinx.roles import xfileref_role
4444

45+
def my_import(name):
46+
"""Module importer - taken from the python documentation.
47+
48+
This function allows importing names with dots in them."""
49+
50+
mod = __import__(name)
51+
components = name.split('.')
52+
for comp in components[1:]:
53+
mod = getattr(mod, comp)
54+
return mod
55+
4556
class DotException(Exception):
4657
pass
4758

@@ -84,6 +95,13 @@ def _import_class_or_module(self, name):
8495
path = base
8596
try:
8697
module = __import__(path, None, None, [])
98+
# We must do an import of the fully qualified name. Otherwise if a
99+
# subpackage 'a.b' is requested where 'import a' does NOT provide
100+
# 'a.b' automatically, then 'a.b' will not be found below. This
101+
# second call will force the equivalent of 'import a.b' to happen
102+
# after the top-level import above.
103+
my_import(fullname)
104+
87105
except ImportError:
88106
raise ValueError(
89107
"Could not import class or module '%s' specified for inheritance diagram" % name)

doc/sphinxext/ipython_console_highlighting.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1+
"""reST directive for syntax-highlighting ipython interactive sessions.
2+
"""
3+
4+
#-----------------------------------------------------------------------------
5+
# Needed modules
6+
7+
# Standard library
8+
import re
9+
10+
# Third party
111
from pygments.lexer import Lexer, do_insertions
2-
from pygments.lexers.agile import PythonConsoleLexer, PythonLexer, \
3-
PythonTracebackLexer
12+
from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
13+
PythonTracebackLexer)
414
from pygments.token import Comment, Generic
15+
516
from sphinx import highlighting
6-
import re
717

18+
19+
#-----------------------------------------------------------------------------
20+
# Global constants
821
line_re = re.compile('.*?\n')
922

23+
#-----------------------------------------------------------------------------
24+
# Code begins - classes and functions
25+
1026
class IPythonConsoleLexer(Lexer):
1127
"""
1228
For IPython console output or doctests, such as:
1329
14-
Tracebacks are not currently supported.
15-
1630
.. sourcecode:: ipython
1731
1832
In [1]: a = 'foo'
@@ -24,7 +38,14 @@ class IPythonConsoleLexer(Lexer):
2438
foo
2539
2640
In [4]: 1 / 0
41+
42+
Notes:
43+
44+
- Tracebacks are not currently supported.
45+
46+
- It assumes the default IPython prompts, not customized ones.
2747
"""
48+
2849
name = 'IPython console session'
2950
aliases = ['ipython']
3051
mimetypes = ['text/x-ipython-console']
@@ -72,4 +93,6 @@ def get_tokens_unprocessed(self, text):
7293
pylexer.get_tokens_unprocessed(curcode)):
7394
yield item
7495

96+
#-----------------------------------------------------------------------------
97+
# Register the extension as a valid pygments lexer
7598
highlighting.lexers['ipython'] = IPythonConsoleLexer()

doc/sphinxext/mathmpl.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
"""matplotlib-based directive for math rendering in reST using sphinx.
2+
3+
To use this extension, add ``mathmpl`` to the list of extensions in
4+
:file:`conf.py`.
5+
6+
Note:
7+
8+
Current SVN versions of Sphinx now include built-in support for math.
9+
There are two flavors:
10+
11+
- pngmath: uses dvipng to render the equation
12+
13+
- jsmath: renders the math in the browser using Javascript
14+
15+
To use these extensions instead of the code in this module, add
16+
``sphinx.ext.pngmath`` or ``sphinx.ext.jsmath`` to the list of extensions in
17+
:file:`conf.py` instead of ``mathmpl``.
18+
19+
All three of these options for math are designed to behave in the same
20+
way.
21+
"""
22+
123
import os
224
import sys
325
try:

doc/sphinxext/only_directives.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
#
2-
# A pair of directives for inserting content that will only appear in
3-
# either html or latex.
4-
#
1+
"""Sphinx directives for selective inclusion of contents.
52
3+
A pair of directives for inserting content that will only appear in
4+
either html or latex.
5+
"""
6+
7+
# Required modules
68
from docutils.nodes import Body, Element
79
from docutils.parsers.rst import directives
810

11+
12+
# Code begins
913
class only_base(Body, Element):
1014
def dont_traverse(self, *args, **kwargs):
1115
return []

0 commit comments

Comments
 (0)