Commit d05917bf authored by Sandro Tosi's avatar Sandro Tosi

add the matplotlib sphinxext directory into doc, needed to build

 documentaion
Forwarded: not-needed
Patch-Name: install_matplotlib_sphinxext
parent bd689cc7
# generate a thumbnail gallery of examples
template = """\
{%% extends "layout.html" %%}
{%% set title = "Thumbnail gallery" %%}
{%% block body %%}
<h3>Click on any image to see full size image and source code</h3>
<br/>
%s
{%% endblock %%}
"""
import os, glob, re, sys, warnings
import matplotlib.image as image
multiimage = re.compile('(.*)_\d\d')
def make_thumbnail(args):
image.thumbnail(args[0], args[1], 0.3)
def out_of_date(original, derived):
return (not os.path.exists(derived) or
os.stat(derived).st_mtime < os.stat(original).st_mtime)
def gen_gallery(app, doctree):
if app.builder.name != 'html':
return
outdir = app.builder.outdir
rootdir = 'plot_directive/mpl_examples'
# images we want to skip for the gallery because they are an unusual
# size that doesn't layout well in a table, or because they may be
# redundant with other images or uninteresting
skips = set([
'mathtext_examples',
'matshow_02',
'matshow_03',
'matplotlib_icon',
])
data = []
thumbnails = {}
for subdir in ('api', 'pylab_examples', 'mplot3d', 'widgets', 'axes_grid' ):
origdir = os.path.join('build', rootdir, subdir)
thumbdir = os.path.join(outdir, rootdir, subdir, 'thumbnails')
if not os.path.exists(thumbdir):
os.makedirs(thumbdir)
for filename in sorted(glob.glob(os.path.join(origdir, '*.png'))):
if filename.endswith("hires.png"):
continue
path, filename = os.path.split(filename)
basename, ext = os.path.splitext(filename)
if basename in skips:
continue
# Create thumbnails based on images in tmpdir, and place
# them within the build tree
orig_path = str(os.path.join(origdir, filename))
thumb_path = str(os.path.join(thumbdir, filename))
if out_of_date(orig_path, thumb_path) or True:
thumbnails[orig_path] = thumb_path
m = multiimage.match(basename)
if m is None:
pyfile = '%s.py'%basename
else:
basename = m.group(1)
pyfile = '%s.py'%basename
data.append((subdir, basename,
os.path.join(rootdir, subdir, 'thumbnails', filename)))
link_template = """\
<a href="%s"><img src="%s" border="0" alt="%s"/></a>
"""
if len(data) == 0:
warnings.warn("No thumbnails were found")
rows = []
for (subdir, basename, thumbfile) in data:
if thumbfile is not None:
link = 'examples/%s/%s.html'%(subdir, basename)
rows.append(link_template%(link, thumbfile, basename))
# Only write out the file if the contents have actually changed.
# Otherwise, this triggers a full rebuild of the docs
content = template%'\n'.join(rows)
gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html')
if os.path.exists(gallery_path):
fh = file(gallery_path, 'r')
regenerate = fh.read() != content
fh.close()
else:
regenerate = True
if regenerate:
fh = file(gallery_path, 'w')
fh.write(content)
fh.close()
try:
import multiprocessing
app.builder.info("generating thumbnails... ", nonl=True)
pool = multiprocessing.Pool()
pool.map(make_thumbnail, thumbnails.iteritems())
pool.close()
pool.join()
app.builder.info("done")
except ImportError:
for key in app.builder.status_iterator(
thumbnails.iterkeys(), "generating thumbnails... ",
length=len(thumbnails)):
image.thumbnail(key, thumbnails[key], 0.3)
def setup(app):
app.connect('env-updated', gen_gallery)
"""
generate the rst files for the examples by iterating over the pylab examples
"""
import os, glob
import os
import re
import sys
fileList = []
def out_of_date(original, derived):
"""
Returns True if derivative is out-of-date wrt original,
both of which are full file paths.
TODO: this check isn't adequate in some cases. Eg, if we discover
a bug when building the examples, the original and derived will be
unchanged but we still want to force a rebuild.
"""
return (not os.path.exists(derived) or
os.stat(derived).st_mtime < os.stat(original).st_mtime)
noplot_regex = re.compile(r"#\s*-\*-\s*noplot\s*-\*-")
def generate_example_rst(app):
rootdir = os.path.join(app.builder.srcdir, 'mpl_examples')
exampledir = os.path.join(app.builder.srcdir, 'examples')
if not os.path.exists(exampledir):
os.makedirs(exampledir)
datad = {}
for root, subFolders, files in os.walk(rootdir):
for fname in files:
if ( fname.startswith('.') or fname.startswith('#') or fname.startswith('_') or
fname.find('.svn')>=0 or not fname.endswith('.py') ):
continue
fullpath = os.path.join(root,fname)
contents = file(fullpath).read()
# indent
relpath = os.path.split(root)[-1]
datad.setdefault(relpath, []).append((fullpath, fname, contents))
subdirs = datad.keys()
subdirs.sort()
fhindex = file(os.path.join(exampledir, 'index.rst'), 'w')
fhindex.write("""\
.. _examples-index:
####################
Matplotlib Examples
####################
.. htmlonly::
:Release: |version|
:Date: |today|
.. toctree::
:maxdepth: 2
""")
for subdir in subdirs:
rstdir = os.path.join(exampledir, subdir)
if not os.path.exists(rstdir):
os.makedirs(rstdir)
outputdir = os.path.join(app.builder.outdir, 'examples')
if not os.path.exists(outputdir):
os.makedirs(outputdir)
outputdir = os.path.join(outputdir, subdir)
if not os.path.exists(outputdir):
os.makedirs(outputdir)
subdirIndexFile = os.path.join(rstdir, 'index.rst')
fhsubdirIndex = file(subdirIndexFile, 'w')
fhindex.write(' %s/index.rst\n\n'%subdir)
fhsubdirIndex.write("""\
.. _%s-examples-index:
##############################################
%s Examples
##############################################
.. htmlonly::
:Release: |version|
:Date: |today|
.. toctree::
:maxdepth: 1
"""%(subdir, subdir))
sys.stdout.write(subdir + ", ")
sys.stdout.flush()
data = datad[subdir]
data.sort()
for fullpath, fname, contents in data:
basename, ext = os.path.splitext(fname)
outputfile = os.path.join(outputdir, fname)
#thumbfile = os.path.join(thumb_dir, '%s.png'%basename)
#print ' static_dir=%s, basename=%s, fullpath=%s, fname=%s, thumb_dir=%s, thumbfile=%s'%(static_dir, basename, fullpath, fname, thumb_dir, thumbfile)
rstfile = '%s.rst'%basename
outrstfile = os.path.join(rstdir, rstfile)
fhsubdirIndex.write(' %s\n'%rstfile)
if not out_of_date(fullpath, outrstfile):
continue
fh = file(outrstfile, 'w')
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
title = '%s example code: %s'%(subdir, fname)
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
fh.write(title + '\n')
fh.write('='*len(title) + '\n\n')
do_plot = (subdir in ('api',
'pylab_examples',
'units',
'mplot3d',
'axes_grid',
) and
not noplot_regex.search(contents))
if do_plot:
fh.write("\n\n.. plot:: %s\n\n::\n\n" % fullpath)
else:
fh.write("[`source code <%s>`_]\n\n::\n\n" % fname)
fhstatic = file(outputfile, 'w')
fhstatic.write(contents)
fhstatic.close()
# indent the contents
contents = '\n'.join([' %s'%row.rstrip() for row in contents.split('\n')])
fh.write(contents)
fh.write('\n\nKeywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)')
fh.close()
fhsubdirIndex.close()
fhindex.close()
print
def setup(app):
app.connect('builder-inited', generate_example_rst)
This diff is collapsed.
symbols = [
["Lower-case Greek",
5,
r"""\alpha \beta \gamma \chi \delta \epsilon \eta \iota \kappa
\lambda \mu \nu \omega \phi \pi \psi \rho \sigma \tau \theta
\upsilon \xi \zeta \digamma \varepsilon \varkappa \varphi
\varpi \varrho \varsigma \vartheta"""],
["Upper-case Greek",
6,
r"""\Delta \Gamma \Lambda \Omega \Phi \Pi \Psi \Sigma \Theta
\Upsilon \Xi \mho \nabla"""],
["Hebrew",
4,
r"""\aleph \beth \daleth \gimel"""],
["Delimiters",
6,
r"""| \{ \lfloor / \Uparrow \llcorner \vert \} \rfloor \backslash
\uparrow \lrcorner \| \langle \lceil [ \Downarrow \ulcorner
\Vert \rangle \rceil ] \downarrow \urcorner"""],
["Big symbols",
5,
r"""\bigcap \bigcup \bigodot \bigoplus \bigotimes \biguplus
\bigvee \bigwedge \coprod \oint \prod \sum \int"""],
["Standard function names",
4,
r"""\arccos \csc \ker \min \arcsin \deg \lg \Pr \arctan \det \lim
\gcd \ln \sup \cot \hom \log \tan \coth \inf \max \tanh
\sec \arg \dim \liminf \sin \cos \exp \limsup \sinh \cosh"""],
["Binary operation and relation symbols",
3,
r"""\ast \pm \slash \cap \star \mp \cup \cdot \uplus
\triangleleft \circ \odot \sqcap \triangleright \bullet \ominus
\sqcup \bigcirc \oplus \wedge \diamond \oslash \vee
\bigtriangledown \times \otimes \dag \bigtriangleup \div \wr
\ddag \barwedge \veebar \boxplus \curlywedge \curlyvee \boxminus
\Cap \Cup \boxtimes \bot \top \dotplus \boxdot \intercal
\rightthreetimes \divideontimes \leftthreetimes \equiv \leq \geq
\perp \cong \prec \succ \mid \neq \preceq \succeq \parallel \sim
\ll \gg \bowtie \simeq \subset \supset \Join \approx \subseteq
\supseteq \ltimes \asymp \sqsubset \sqsupset \rtimes \doteq
\sqsubseteq \sqsupseteq \smile \propto \dashv \vdash \frown
\models \in \ni \notin \approxeq \leqq \geqq \lessgtr \leqslant
\geqslant \lesseqgtr \backsim \lessapprox \gtrapprox \lesseqqgtr
\backsimeq \lll \ggg \gtreqqless \triangleq \lessdot \gtrdot
\gtreqless \circeq \lesssim \gtrsim \gtrless \bumpeq \eqslantless
\eqslantgtr \backepsilon \Bumpeq \precsim \succsim \between
\doteqdot \precapprox \succapprox \pitchfork \Subset \Supset
\fallingdotseq \subseteqq \supseteqq \risingdotseq \sqsubset
\sqsupset \varpropto \preccurlyeq \succcurlyeq \Vdash \therefore
\curlyeqprec \curlyeqsucc \vDash \because \blacktriangleleft
\blacktriangleright \Vvdash \eqcirc \trianglelefteq
\trianglerighteq \neq \vartriangleleft \vartriangleright \ncong
\nleq \ngeq \nsubseteq \nmid \nsupseteq \nparallel \nless \ngtr
\nprec \nsucc \subsetneq \nsim \supsetneq \nVDash \precnapprox
\succnapprox \subsetneqq \nvDash \precnsim \succnsim \supsetneqq
\nvdash \lnapprox \gnapprox \ntriangleleft \ntrianglelefteq
\lneqq \gneqq \ntriangleright \lnsim \gnsim \ntrianglerighteq
\coloneq \eqsim \nequiv \napprox \nsupset \doublebarwedge \nVdash
\Doteq \nsubset \eqcolon \ne
"""],
["Arrow symbols",
2,
r"""\leftarrow \longleftarrow \uparrow \Leftarrow \Longleftarrow
\Uparrow \rightarrow \longrightarrow \downarrow \Rightarrow
\Longrightarrow \Downarrow \leftrightarrow \updownarrow
\longleftrightarrow \updownarrow \Leftrightarrow
\Longleftrightarrow \Updownarrow \mapsto \longmapsto \nearrow
\hookleftarrow \hookrightarrow \searrow \leftharpoonup
\rightharpoonup \swarrow \leftharpoondown \rightharpoondown
\nwarrow \rightleftharpoons \leadsto \dashrightarrow
\dashleftarrow \leftleftarrows \leftrightarrows \Lleftarrow
\Rrightarrow \twoheadleftarrow \leftarrowtail \looparrowleft
\leftrightharpoons \curvearrowleft \circlearrowleft \Lsh
\upuparrows \upharpoonleft \downharpoonleft \multimap
\leftrightsquigarrow \rightrightarrows \rightleftarrows
\rightrightarrows \rightleftarrows \twoheadrightarrow
\rightarrowtail \looparrowright \rightleftharpoons
\curvearrowright \circlearrowright \Rsh \downdownarrows
\upharpoonright \downharpoonright \rightsquigarrow \nleftarrow
\nrightarrow \nLeftarrow \nRightarrow \nleftrightarrow
\nLeftrightarrow \to \Swarrow \Searrow \Nwarrow \Nearrow
\leftsquigarrow
"""],
["Miscellaneous symbols",
3,
r"""\neg \infty \forall \wp \exists \bigstar \angle \partial
\nexists \measuredangle \eth \emptyset \sphericalangle \clubsuit
\varnothing \complement \diamondsuit \imath \Finv \triangledown
\heartsuit \jmath \Game \spadesuit \ell \hbar \vartriangle \cdots
\hslash \vdots \blacksquare \ldots \blacktriangle \ddots \sharp
\prime \blacktriangledown \Im \flat \backprime \Re \natural
\circledS \P \copyright \ss \circledR \S \yen \AA \checkmark \$
\iiint \iint \iint \oiiint"""]
]
def run(state_machine):
def get_n(n, l):
part = []
for x in l:
part.append(x)
if len(part) == n:
yield part
part = []
yield part
lines = []
for category, columns, syms in symbols:
syms = syms.split()
syms.sort()
lines.append("**%s**" % category)
lines.append('')
max_width = 0
for sym in syms:
max_width = max(max_width, len(sym))
max_width = max_width * 2 + 16
header = " " + (('=' * max_width) + ' ') * columns
format = '%%%ds' % max_width
for chunk in get_n(20, get_n(columns, syms)):
lines.append(header)
for part in chunk:
line = []
for sym in part:
line.append(format % (":math:`%s` ``%s``" % (sym, sym)))
lines.append(" " + " ".join(line))
lines.append(header)
lines.append('')
state_machine.insert_input(lines, "Symbol table")
return []
def math_symbol_table_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
return run(state_machine)
def setup(app):
app.add_directive(
'math_symbol_table', math_symbol_table_directive,
False, (0, 1, 0))
if __name__ == "__main__":
# Do some verification of the tables
from matplotlib import _mathtext_data
print "SYMBOLS NOT IN STIX:"
all_symbols = {}
for category, columns, syms in symbols:
if category == "Standard Function Names":
continue
syms = syms.split()
for sym in syms:
if len(sym) > 1:
all_symbols[sym[1:]] = None
if sym[1:] not in _mathtext_data.tex2uni:
print sym
print "SYMBOLS NOT IN TABLE:"
for sym in _mathtext_data.tex2uni:
if sym not in all_symbols:
print sym
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment