From: <md...@us...> - 2008-12-18 19:10:43
|
Revision: 6674 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6674&view=rev Author: mdboom Date: 2008-12-18 19:10:38 +0000 (Thu, 18 Dec 2008) Log Message: ----------- Merged revisions 6672-6673 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r6672 | mdboom | 2008-12-18 14:07:08 -0500 (Thu, 18 Dec 2008) | 2 lines Fix how example files are added to the build. Saves about 1MB in html output. ........ r6673 | mdboom | 2008-12-18 14:08:45 -0500 (Thu, 18 Dec 2008) | 1 line removing examples from svn ........ Modified Paths: -------------- trunk/matplotlib/doc/conf.py trunk/matplotlib/doc/make.py trunk/matplotlib/doc/sphinxext/plot_directive.py trunk/matplotlib/lib/matplotlib/pyplot.py Added Paths: ----------- trunk/matplotlib/doc/sphinxext/gen_rst.py Removed Paths: ------------- trunk/matplotlib/doc/examples/ Property Changed: ---------------- trunk/matplotlib/ trunk/matplotlib/doc/pyplots/README trunk/matplotlib/doc/sphinxext/gen_gallery.py Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6668 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6673 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673 Modified: trunk/matplotlib/doc/conf.py =================================================================== --- trunk/matplotlib/doc/conf.py 2008-12-18 19:08:45 UTC (rev 6673) +++ trunk/matplotlib/doc/conf.py 2008-12-18 19:10:38 UTC (rev 6674) @@ -29,7 +29,7 @@ # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['mathmpl', 'math_symbol_table', 'sphinx.ext.autodoc', 'only_directives', 'plot_directive', 'inheritance_diagram', - 'gen_gallery'] + 'gen_gallery', 'gen_rst'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] Modified: trunk/matplotlib/doc/make.py =================================================================== --- trunk/matplotlib/doc/make.py 2008-12-18 19:08:45 UTC (rev 6673) +++ trunk/matplotlib/doc/make.py 2008-12-18 19:10:38 UTC (rev 6674) @@ -34,15 +34,12 @@ def html(): check_build() - if not os.path.exists('examples/index.rst'): - examples() shutil.copy('../lib/matplotlib/mpl-data/matplotlibrc', '_static/matplotlibrc') - #figs() if small_docs: options = "-D plot_formats=\"['png']\"" else: options = '' - if os.system('sphinx-build %s -b html -d build/doctrees . build/html' % options): + if os.system('sphinx-build %s -P -b html -d build/doctrees . build/html' % options): raise SystemExit("Building HTML failed.") figures_dest_path = 'build/html/pyplots' Property changes on: trunk/matplotlib/doc/pyplots/README ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662 + /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673 Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662 + /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673 Copied: trunk/matplotlib/doc/sphinxext/gen_rst.py (from rev 6673, branches/v0_98_5_maint/doc/sphinxext/gen_rst.py) =================================================================== --- trunk/matplotlib/doc/sphinxext/gen_rst.py (rev 0) +++ trunk/matplotlib/doc/sphinxext/gen_rst.py 2008-12-18 19:10:38 UTC (rev 6674) @@ -0,0 +1,155 @@ +""" +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)) + + print subdir + + 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, outputfile) and + not out_of_date(fullpath, outrstfile)): + continue + + print ' %s'%fname + + 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') 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() + +def setup(app): + app.connect('builder-inited', generate_example_rst) Modified: trunk/matplotlib/doc/sphinxext/plot_directive.py =================================================================== --- trunk/matplotlib/doc/sphinxext/plot_directive.py 2008-12-18 19:08:45 UTC (rev 6673) +++ trunk/matplotlib/doc/sphinxext/plot_directive.py 2008-12-18 19:10:38 UTC (rev 6674) @@ -34,6 +34,41 @@ import matplotlib.image as image from matplotlib import _pylab_helpers +if hasattr(os.path, 'relpath'): + relpath = os.path.relpath +else: + def relpath(target, base=os.curdir): + """ + Return a relative path to the target from either the current dir or an optional base dir. + Base can be a directory specified either as absolute or relative to current dir. + """ + + if not os.path.exists(target): + raise OSError, 'Target does not exist: '+target + + if not os.path.isdir(base): + raise OSError, 'Base is not a directory or does not exist: '+base + + base_list = (os.path.abspath(base)).split(os.sep) + target_list = (os.path.abspath(target)).split(os.sep) + + # On the windows platform the target may be on a completely different drive from the base. + if os.name in ['nt','dos','os2'] and base_list[0] <> target_list[0]: + raise OSError, 'Target is on a different drive to base. Target: '+target_list[0].upper()+', base: '+base_list[0].upper() + + # Starting from the filepath root, work out how much of the filepath is + # shared by base and target. + for i in range(min(len(base_list), len(target_list))): + if base_list[i] <> target_list[i]: break + else: + # If we broke out of the loop, i is pointing to the first differing path elements. + # If we didn't break out of the loop, i is pointing to identical path elements. + # Increment i so that in all cases it points to the first differing path elements. + i+=1 + + rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:] + return os.path.join(*rel_list) + def write_char(s): sys.stdout.write(s) sys.stdout.flush() @@ -186,6 +221,7 @@ reference = directives.uri(arguments[0]) basedir, fname = os.path.split(reference) basename, ext = os.path.splitext(fname) + basedir = relpath(basedir, setup.app.builder.srcdir) # Get the directory of the rst file, and determine the relative # path from the resulting html file to the plot_directive links Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-12-18 19:08:45 UTC (rev 6673) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-12-18 19:10:38 UTC (rev 6674) @@ -1148,10 +1148,9 @@ def plotting(): """ Plotting commands - - ============ ================================================= + =============== ========================================================= Command Description - ========= ================================================= + =============== ========================================================= axes Create a new axes axis Set or return the current axis limits bar make a bar chart @@ -1204,7 +1203,7 @@ title add a title to the current axes xlabel add an xlabel to the current axes ylabel add a ylabel to the current axes - ============ ================================================= + =============== ========================================================= The following commands will set the default colormap accordingly: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |