Skip to content

Commit

Permalink
Merge pull request #1897 from mdboom/doc/encoding_gen_rst
Browse files Browse the repository at this point in the history
Fix documentation build failure (unicode error in generate_example_rst)
  • Loading branch information
pelson committed Apr 17, 2013
2 parents b9d3422 + 1ed2b1a commit 077b26f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
8 changes: 4 additions & 4 deletions doc/conf.py
Expand Up @@ -16,19 +16,19 @@
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
sys.path.append(os.path.abspath('sphinxext'))
sys.path.append(os.path.abspath('.'))

# General configuration
# ---------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['matplotlib.sphinxext.mathmpl', 'math_symbol_table',
extensions = ['matplotlib.sphinxext.mathmpl', 'sphinxext.math_symbol_table',
'sphinx.ext.autodoc', 'matplotlib.sphinxext.only_directives',
'sphinx.ext.doctest',
'matplotlib.sphinxext.plot_directive', 'sphinx.ext.inheritance_diagram',
'gen_gallery', 'gen_rst',
'matplotlib.sphinxext.ipython_console_highlighting', 'github']
'sphinxext.gen_gallery', 'sphinxext.gen_rst',
'matplotlib.sphinxext.ipython_console_highlighting', 'sphinxext.github']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
Empty file added doc/sphinxext/__init__.py
Empty file.
26 changes: 10 additions & 16 deletions doc/sphinxext/gen_rst.py
Expand Up @@ -38,10 +38,7 @@ def generate_example_rst(app):
continue

fullpath = os.path.join(root,fname)
if sys.version_info[0] >= 3:
contents = io.open(fullpath, encoding='utf8').read()
else:
contents = io.open(fullpath).read()
contents = io.open(fullpath, encoding='utf8').read()
# indent
relpath = os.path.split(root)[-1]
datad.setdefault(relpath, []).append((fullpath, fname, contents))
Expand Down Expand Up @@ -126,34 +123,31 @@ def generate_example_rst(app):
) and
not noplot_regex.search(contents))
if not do_plot:
fhstatic = open(outputfile, 'w')
fhstatic = io.open(outputfile, 'w', encoding='utf-8')
fhstatic.write(contents)
fhstatic.close()

if not out_of_date(fullpath, outrstfile):
continue

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))
fh = io.open(outrstfile, 'w', encoding='utf-8')
fh.write(u'.. _%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')
fh.write(title + u'\n')
fh.write(u'=' * len(title) + u'\n\n')

if do_plot:
fh.write("\n\n.. plot:: %s\n\n::\n\n" % fullpath)
fh.write(u"\n\n.. plot:: %s\n\n::\n\n" % fullpath)
else:
fh.write("[`source code <%s>`_]\n\n::\n\n" % fname)
fh.write(u"[`source code <%s>`_]\n\n::\n\n" % fname)

# indent the contents
contents = '\n'.join([' %s'%row.rstrip() for row in contents.split('\n')])
contents = u'\n'.join([u' %s'%row.rstrip() for row in contents.split(u'\n')])
fh.write(contents)

fh.write('\n\nKeywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)')
fh.write(u'\n\nKeywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)')
fh.close()

fhsubdirIndex.close()
Expand Down

0 comments on commit 077b26f

Please sign in to comment.