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

Skip to content

More fixes for doc building with python 3 #1383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions doc/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ 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
else:
errors.extend((src, dst, str(why)))
if errors:
raise Error, errors
raise Error(errors)

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

Expand Down
6 changes: 3 additions & 3 deletions doc/sphinxext/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 13 additions & 6 deletions doc/sphinxext/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,15 +38,18 @@ def generate_example_rst(app):
continue

fullpath = os.path.join(root,fname)
contents = file(fullpath).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))

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:

Expand Down Expand Up @@ -77,7 +81,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("""\
Expand Down Expand Up @@ -122,14 +126,17 @@ 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')
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 = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/sphinxext/mathmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down