Fix support for Sphinx 1.3

This commit is contained in:
Steven Silvester
2015-03-14 10:35:04 -05:00
parent 7d65366b67
commit 9c3a6c1e91
2 changed files with 14 additions and 7 deletions
+9 -6
View File
@@ -186,6 +186,11 @@ def setup(app):
def generate_example_galleries(app): def generate_example_galleries(app):
cfg = app.builder.config cfg = app.builder.config
if isinstance(cfg.source_suffix, list):
cfg.source_suffix_str = cfg.source_suffix[0]
else:
cfg.source_suffix_str = cfg.source_suffix
doc_src = Path(os.path.abspath(app.builder.srcdir)) # path/to/doc/source doc_src = Path(os.path.abspath(app.builder.srcdir)) # path/to/doc/source
if isinstance(cfg.plot2rst_paths, tuple): if isinstance(cfg.plot2rst_paths, tuple):
@@ -205,10 +210,7 @@ def generate_examples_and_gallery(example_dir, rst_dir, cfg):
rst_dir.makedirs() rst_dir.makedirs()
# we create an index.rst with all examples # we create an index.rst with all examples
if isinstance(cfg.source_suffix, list): gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix_str), 'w')
cfg.source_suffix = cfg.source_suffix[0]
gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix), 'w')
# Here we don't use an os.walk, but we recurse only twice: flat is # Here we don't use an os.walk, but we recurse only twice: flat is
# better than nested. # better than nested.
@@ -238,7 +240,7 @@ def write_gallery(gallery_index, src_dir, rst_dir, cfg, depth=0):
cfg : config object cfg : config object
Sphinx config object created by Sphinx. Sphinx config object created by Sphinx.
""" """
index_name = cfg.plot2rst_index_name + cfg.source_suffix index_name = cfg.plot2rst_index_name + cfg.source_suffix_str
gallery_template = src_dir.pjoin(index_name) gallery_template = src_dir.pjoin(index_name)
if not os.path.exists(gallery_template): if not os.path.exists(gallery_template):
print(src_dir) print(src_dir)
@@ -331,7 +333,8 @@ def write_example(src_name, src_dir, rst_dir, cfg):
image_path = image_dir.pjoin(base_image_name + '_{0}.png') image_path = image_dir.pjoin(base_image_name + '_{0}.png')
basename, py_ext = os.path.splitext(src_name) basename, py_ext = os.path.splitext(src_name)
rst_path = rst_dir.pjoin(basename + cfg.source_suffix)
rst_path = rst_dir.pjoin(basename + cfg.source_suffix_str)
notebook_path = notebook_dir.pjoin(basename + '.ipynb') notebook_path = notebook_dir.pjoin(basename + '.ipynb')
if _plots_are_current(src_path, image_path) and rst_path.exists and \ if _plots_are_current(src_path, image_path) and rst_path.exists and \
+5 -1
View File
@@ -12,6 +12,7 @@
# serve to show the default. # serve to show the default.
import sys, os import sys, os
import sphinx
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
@@ -50,7 +51,10 @@ else:
templates_path = ['_templates'] templates_path = ['_templates']
# The suffix of source filenames. # The suffix of source filenames.
source_suffix = '.txt' if sphinx.__version__.startswith('1.3'):
source_suffix = ['.txt']
else:
source_suffix = '.txt'
# The encoding of source files. # The encoding of source files.
#source_encoding = 'utf-8-sig' #source_encoding = 'utf-8-sig'