Skip to content

Commit 1d6abc1

Browse files
committed
Merge pull request #1383 from dmcdougall/py3_docs_2
More fixes for doc building with python 3
2 parents bf81d2b + 5e36bb7 commit 1d6abc1

File tree

6 files changed

+27
-20
lines changed

6 files changed

+27
-20
lines changed

doc/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@
174174

175175
# Additional stuff for the LaTeX preamble.
176176
latex_preamble = """
177-
\usepackage{amsmath}
178-
\usepackage{amsfonts}
179-
\usepackage{amssymb}
180-
\usepackage{txfonts}
177+
\\usepackage{amsmath}
178+
\\usepackage{amsfonts}
179+
\\usepackage{amssymb}
180+
\\usepackage{txfonts}
181181
"""
182182

183183
# Documents to append as an appendix to all manuals.

doc/make.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ def copytree(src, dst, symlinks=False, ignore=None):
8989
copy2(srcname, dstname)
9090
# catch the Error from the recursive copytree so that we can
9191
# continue with other files
92-
except Error, err:
92+
except Error as err:
9393
errors.extend(err.args[0])
94-
except EnvironmentError, why:
94+
except EnvironmentError as why:
9595
errors.append((srcname, dstname, str(why)))
9696
try:
9797
copystat(src, dst)
98-
except OSError, why:
98+
except OSError as why:
9999
if WindowsError is not None and isinstance(why, WindowsError):
100100
# Copying file access times may fail on Windows
101101
pass
102102
else:
103103
errors.extend((src, dst, str(why)))
104104
if errors:
105-
raise Error, errors
105+
raise Error(errors)
106106

107107
### End compatibility block for pre-v2.6 ###
108108

doc/sphinxext/gen_gallery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@ def gen_gallery(app, doctree):
121121

122122
gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html')
123123
if os.path.exists(gallery_path):
124-
fh = file(gallery_path, 'r')
124+
fh = open(gallery_path, 'r')
125125
regenerate = fh.read() != content
126126
fh.close()
127127
else:
128128
regenerate = True
129129
if regenerate:
130-
fh = file(gallery_path, 'w')
130+
fh = open(gallery_path, 'w')
131131
fh.write(content)
132132
fh.close()
133133

134134
for key in app.builder.status_iterator(
135-
thumbnails.iterkeys(), "generating thumbnails... ",
135+
iter(thumbnails.keys()), "generating thumbnails... ",
136136
length=len(thumbnails)):
137137
image.thumbnail(key, thumbnails[key], 0.3)
138138

doc/sphinxext/gen_rst.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
generate the rst files for the examples by iterating over the pylab examples
33
"""
44
from __future__ import print_function
5+
import io
56
import os, glob
67

78
import os
@@ -37,15 +38,18 @@ def generate_example_rst(app):
3738
continue
3839

3940
fullpath = os.path.join(root,fname)
40-
contents = file(fullpath).read()
41+
if sys.version_info[0] >= 3:
42+
contents = io.open(fullpath, encoding='utf8').read()
43+
else:
44+
contents = io.open(fullpath).read()
4145
# indent
4246
relpath = os.path.split(root)[-1]
4347
datad.setdefault(relpath, []).append((fullpath, fname, contents))
4448

45-
subdirs = datad.keys()
49+
subdirs = list(datad.keys())
4650
subdirs.sort()
4751

48-
fhindex = file(os.path.join(exampledir, 'index.rst'), 'w')
52+
fhindex = open(os.path.join(exampledir, 'index.rst'), 'w')
4953
fhindex.write("""\
5054
.. _examples-index:
5155
@@ -77,7 +81,7 @@ def generate_example_rst(app):
7781
os.makedirs(outputdir)
7882

7983
subdirIndexFile = os.path.join(rstdir, 'index.rst')
80-
fhsubdirIndex = file(subdirIndexFile, 'w')
84+
fhsubdirIndex = open(subdirIndexFile, 'w')
8185
fhindex.write(' %s/index.rst\n\n'%subdir)
8286

8387
fhsubdirIndex.write("""\
@@ -122,14 +126,17 @@ def generate_example_rst(app):
122126
) and
123127
not noplot_regex.search(contents))
124128
if not do_plot:
125-
fhstatic = file(outputfile, 'w')
129+
fhstatic = open(outputfile, 'w')
126130
fhstatic.write(contents)
127131
fhstatic.close()
128132

129133
if not out_of_date(fullpath, outrstfile):
130134
continue
131135

132-
fh = file(outrstfile, 'w')
136+
if sys.version_info[0] >= 3:
137+
fh = io.open(outrstfile, 'w', encoding='utf8')
138+
else:
139+
fh = io.open(outrstfile, 'w')
133140
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
134141
title = '%s example code: %s'%(subdir, fname)
135142
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)

lib/matplotlib/sphinxext/mathmpl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def latex2png(latex, filename, fontset='cm'):
6565
def latex2html(node, source):
6666
inline = isinstance(node.parent, nodes.TextElement)
6767
latex = node['latex']
68-
name = 'math-%s' % md5(latex).hexdigest()[-10:]
68+
name = 'math-%s' % md5(latex.encode()).hexdigest()[-10:]
6969

7070
destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl')
7171
if not os.path.exists(destdir):

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
"""
126126
from __future__ import print_function
127127

128-
import sys, os, glob, shutil, imp, warnings, cStringIO, re, textwrap, \
129-
traceback, exceptions
128+
import sys, os, glob, shutil, imp, warnings, cStringIO, re, textwrap
129+
import traceback
130130

131131
from docutils.parsers.rst import directives
132132
from docutils import nodes

0 commit comments

Comments
 (0)