From df93ecada6237a24852d9ac52c09fa10f1298b22 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Sat, 13 Oct 2012 18:07:27 +0100 Subject: [PATCH 1/8] Make conf.py work with py3 --- doc/conf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 03ca7061a926..ceb41bd84aa7 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -174,10 +174,10 @@ # Additional stuff for the LaTeX preamble. latex_preamble = """ - \usepackage{amsmath} - \usepackage{amsfonts} - \usepackage{amssymb} - \usepackage{txfonts} + \\usepackage{amsmath} + \\usepackage{amsfonts} + \\usepackage{amssymb} + \\usepackage{txfonts} """ # Documents to append as an appendix to all manuals. From 19b1a05182660199036c4426ce169b12f446810c Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Sat, 13 Oct 2012 18:16:23 +0100 Subject: [PATCH 2/8] Make gen_rst behave with py3 --- doc/sphinxext/gen_rst.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/sphinxext/gen_rst.py b/doc/sphinxext/gen_rst.py index e8135bf4abdb..09c3e47ba99c 100644 --- a/doc/sphinxext/gen_rst.py +++ b/doc/sphinxext/gen_rst.py @@ -2,6 +2,7 @@ generate the rst files for the examples by iterating over the pylab examples """ from __future__ import print_function +import io import os, glob import os @@ -37,15 +38,15 @@ def generate_example_rst(app): continue fullpath = os.path.join(root,fname) - contents = file(fullpath).read() + contents = io.open(fullpath, encoding='utf8').read() # indent relpath = os.path.split(root)[-1] datad.setdefault(relpath, []).append((fullpath, fname, contents)) - subdirs = datad.keys() + subdirs = list(datad.keys()) subdirs.sort() - fhindex = file(os.path.join(exampledir, 'index.rst'), 'w') + fhindex = open(os.path.join(exampledir, 'index.rst'), 'w') fhindex.write("""\ .. _examples-index: @@ -77,7 +78,7 @@ def generate_example_rst(app): os.makedirs(outputdir) subdirIndexFile = os.path.join(rstdir, 'index.rst') - fhsubdirIndex = file(subdirIndexFile, 'w') + fhsubdirIndex = open(subdirIndexFile, 'w') fhindex.write(' %s/index.rst\n\n'%subdir) fhsubdirIndex.write("""\ @@ -122,14 +123,14 @@ def generate_example_rst(app): ) and not noplot_regex.search(contents)) if not do_plot: - fhstatic = file(outputfile, 'w') + fhstatic = open(outputfile, 'w') fhstatic.write(contents) fhstatic.close() if not out_of_date(fullpath, outrstfile): continue - fh = file(outrstfile, 'w') + fh = io.open(outrstfile, 'w', encoding='utf8') fh.write('.. _%s-%s:\n\n'%(subdir, basename)) title = '%s example code: %s'%(subdir, fname) #title = ' %s example code: %s'%(thumbfile, subdir, fname) From 818cf19599cae4c878fe3813679c93b2fb360a88 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Mon, 15 Oct 2012 21:40:31 +0100 Subject: [PATCH 3/8] Make plot_directive py3 friendly --- lib/matplotlib/sphinxext/plot_directive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index ac96d5fa3568..e0a6c53709fb 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -125,8 +125,8 @@ """ from __future__ import print_function -import sys, os, glob, shutil, imp, warnings, cStringIO, re, textwrap, \ - traceback, exceptions +import sys, os, glob, shutil, imp, warnings, cStringIO, re, textwrap +import traceback from docutils.parsers.rst import directives from docutils import nodes From 91319b1e7febfdbca3d796f5242b74a5d95b8181 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Wed, 10 Oct 2012 23:19:14 +0200 Subject: [PATCH 4/8] Make make.py build docs under python 3 --- doc/make.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/make.py b/doc/make.py index 7df050d13ad4..4629e2667d48 100755 --- a/doc/make.py +++ b/doc/make.py @@ -89,13 +89,13 @@ def copytree(src, dst, symlinks=False, ignore=None): copy2(srcname, dstname) # catch the Error from the recursive copytree so that we can # continue with other files - except Error, err: + except Error as err: errors.extend(err.args[0]) - except EnvironmentError, why: + except EnvironmentError as why: errors.append((srcname, dstname, str(why))) try: copystat(src, dst) - except OSError, why: + except OSError as why: if WindowsError is not None and isinstance(why, WindowsError): # Copying file access times may fail on Windows pass From 222e742cd9d9f5b33923e4144da9fa4fce4d556d Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Fri, 12 Oct 2012 20:18:09 +0200 Subject: [PATCH 5/8] Make call to raise py3 compatible --- doc/make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/make.py b/doc/make.py index 4629e2667d48..8e37ec7f6e36 100755 --- a/doc/make.py +++ b/doc/make.py @@ -102,7 +102,7 @@ def copytree(src, dst, symlinks=False, ignore=None): else: errors.extend((src, dst, str(why))) if errors: - raise Error, errors + raise Error(errors) ### End compatibility block for pre-v2.6 ### From 196636f0995f75a2303236ec5347a3d04b6f643f Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Tue, 16 Oct 2012 09:45:50 +0100 Subject: [PATCH 6/8] Fix py2/3 unicode differences --- doc/sphinxext/gen_rst.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/sphinxext/gen_rst.py b/doc/sphinxext/gen_rst.py index 09c3e47ba99c..a251917fe490 100644 --- a/doc/sphinxext/gen_rst.py +++ b/doc/sphinxext/gen_rst.py @@ -38,7 +38,10 @@ def generate_example_rst(app): continue fullpath = os.path.join(root,fname) - contents = io.open(fullpath, encoding='utf8').read() + if sys.version_info[0] >= 3: + contents = io.open(fullpath, encoding='utf8').read() + else: + contents = io.open(fullpath).read() # indent relpath = os.path.split(root)[-1] datad.setdefault(relpath, []).append((fullpath, fname, contents)) @@ -130,7 +133,10 @@ def generate_example_rst(app): if not out_of_date(fullpath, outrstfile): continue - fh = io.open(outrstfile, 'w', encoding='utf8') + if sys.version_info[0] >= 3: + fh = io.open(outrstfile, 'w', encoding='utf8') + else: + fh = io.open(outrstfile, 'w') fh.write('.. _%s-%s:\n\n'%(subdir, basename)) title = '%s example code: %s'%(subdir, fname) #title = ' %s example code: %s'%(thumbfile, subdir, fname) From 600fd2d294fb2f2bb10858f615e257dec0f01edb Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Tue, 16 Oct 2012 09:52:47 +0100 Subject: [PATCH 7/8] Simple 2to3 on gen_gallery.py --- doc/sphinxext/gen_gallery.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/sphinxext/gen_gallery.py b/doc/sphinxext/gen_gallery.py index 609829262933..0e2eb25c09f5 100644 --- a/doc/sphinxext/gen_gallery.py +++ b/doc/sphinxext/gen_gallery.py @@ -121,18 +121,18 @@ def gen_gallery(app, doctree): gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html') if os.path.exists(gallery_path): - fh = file(gallery_path, 'r') + fh = open(gallery_path, 'r') regenerate = fh.read() != content fh.close() else: regenerate = True if regenerate: - fh = file(gallery_path, 'w') + fh = open(gallery_path, 'w') fh.write(content) fh.close() for key in app.builder.status_iterator( - thumbnails.iterkeys(), "generating thumbnails... ", + iter(thumbnails.keys()), "generating thumbnails... ", length=len(thumbnails)): image.thumbnail(key, thumbnails[key], 0.3) From 5e36bb75440a58b3291b2fc41c6dc2a710afc7ca Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Tue, 16 Oct 2012 10:04:25 +0100 Subject: [PATCH 8/8] Make md5 take byte as argument, not string --- lib/matplotlib/sphinxext/mathmpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/sphinxext/mathmpl.py b/lib/matplotlib/sphinxext/mathmpl.py index 0c126a66b02e..4cbadf092828 100644 --- a/lib/matplotlib/sphinxext/mathmpl.py +++ b/lib/matplotlib/sphinxext/mathmpl.py @@ -65,7 +65,7 @@ def latex2png(latex, filename, fontset='cm'): def latex2html(node, source): inline = isinstance(node.parent, nodes.TextElement) latex = node['latex'] - name = 'math-%s' % md5(latex).hexdigest()[-10:] + name = 'math-%s' % md5(latex.encode()).hexdigest()[-10:] destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl') if not os.path.exists(destdir):