From 9c3a6c1e9140dfd4e334ae4c4e8104604eb60073 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 14 Mar 2015 10:35:04 -0500 Subject: [PATCH] Fix support for Sphinx 1.3 --- doc/ext/plot2rst.py | 15 +++++++++------ doc/source/conf.py | 6 +++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py index 1a35a8a2..32811deb 100644 --- a/doc/ext/plot2rst.py +++ b/doc/ext/plot2rst.py @@ -186,6 +186,11 @@ def setup(app): def generate_example_galleries(app): 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 if isinstance(cfg.plot2rst_paths, tuple): @@ -205,10 +210,7 @@ def generate_examples_and_gallery(example_dir, rst_dir, cfg): rst_dir.makedirs() # we create an index.rst with all examples - if isinstance(cfg.source_suffix, list): - cfg.source_suffix = cfg.source_suffix[0] - - gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix), 'w') + gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix_str), 'w') # Here we don't use an os.walk, but we recurse only twice: flat is # better than nested. @@ -238,7 +240,7 @@ def write_gallery(gallery_index, src_dir, rst_dir, cfg, depth=0): cfg : config object 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) if not os.path.exists(gallery_template): 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') 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') if _plots_are_current(src_path, image_path) and rst_path.exists and \ diff --git a/doc/source/conf.py b/doc/source/conf.py index 94904305..be2d0790 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -12,6 +12,7 @@ # serve to show the default. import sys, os +import sphinx # 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 @@ -50,7 +51,10 @@ else: templates_path = ['_templates'] # 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. #source_encoding = 'utf-8-sig'