Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 614a4f4

Browse filesBrowse files
committed
MNT: refactor format toctree
1 parent f58b4f3 commit 614a4f4
Copy full SHA for 614a4f4

File tree

Expand file treeCollapse file tree

3 files changed

+36
-27
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+36
-27
lines changed

‎doc/configuration.rst

Copy file name to clipboardExpand all lines: doc/configuration.rst
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,11 +1898,14 @@ in your document. You can, of course, add a ``toctree`` to your
18981898
Manually passing ``index.rst``
18991899
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19001900

1901-
If you want control over the gallery (or subgallery) ``index.rst``, you
1902-
can bypass Sphinx-Gallery creating it from ``README.txt`` by including
1903-
it in the gallery-source instead of the README. If you do this, you are
1904-
responsible for building your own ``toctree`` in that index or elsewhere
1905-
that includes the gallery items.
1901+
You can bypass Sphinx-Gallery automatically creating an index ``index.rst``
1902+
from a ``README.txt`` in a gallery directory or subdirectory. If your
1903+
``copyfile_regex`` includes ``index.rst``, and you have an ``index.rst`` in the
1904+
gallery-source instead of the README, Sphinx-Gallery will use that instead of
1905+
the index it automatically makes. If you do this, you are responsible for
1906+
adding your own Sphinx ``toctree`` in that index (or elsewhere in your Sphinx
1907+
documentation) that includes any gallery items or other files in that
1908+
directory.
19061909

19071910
.. _show_api_usage:
19081911

‎sphinx_gallery/gen_gallery.py

Copy file name to clipboardExpand all lines: sphinx_gallery/gen_gallery.py
+26-21Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,24 @@ def _prepare_sphx_glr_dirs(gallery_conf, srcdir):
457457
return list(zip(examples_dirs, gallery_dirs))
458458

459459

460+
def _format_toctree(items, includehidden=False):
461+
"""Format a toc tree"""
462+
463+
st = """
464+
.. toctree::
465+
:hidden:
466+
"""
467+
if includehidden:
468+
st += """
469+
:includehidden:
470+
"""
471+
st += """
472+
473+
%s\n""" % "\n ".join(items)
474+
475+
return st
476+
477+
460478
def generate_gallery_rst(app):
461479
"""Generate the Main examples gallery reStructuredText
462480
@@ -519,21 +537,18 @@ def generate_gallery_rst(app):
519537
# (this will overwrite the rst file generated by the previous call
520538
# to generate_dir_rst)
521539

522-
# :orphan: to suppress "not included in TOCTREE" sphinx
523-
# warnings
524540
if this_content:
541+
# :orphan: to suppress "not included in TOCTREE" sphinx warnings
525542
indexst = ":orphan:\n\n" + this_content
526543
else:
544+
# we are not going to use the index.rst.new that gets made here,
545+
# but go through the motions to run through all the subsections...
527546
indexst = 'Never used!'
528547

529548
# Write toctree with gallery items from gallery root folder
530549
if len(this_toctree_items) > 0:
531-
this_toctree = """
532-
.. toctree::
533-
:hidden:
550+
this_toctree = _format_toctree(this_toctree_items)
534551

535-
%s\n
536-
""" % "\n ".join(this_toctree_items)
537552
indexst += this_toctree
538553

539554
# list all paths to subsection index files in this array
@@ -575,12 +590,8 @@ def generate_gallery_rst(app):
575590
# toctree filenames were generated for the subsection.
576591
if not gallery_conf["nested_sections"]:
577592
if len(subsection_toctree_filenames) > 0:
578-
subsection_index_toctree = """
579-
.. toctree::
580-
:hidden:
581-
582-
%s\n
583-
""" % "\n ".join(subsection_toctree_filenames)
593+
subsection_index_toctree = _format_toctree(
594+
subsection_toctree_filenames)
584595
indexst += subsection_index_toctree
585596
# Otherwise, a new index.rst.new file should
586597
# have been created and it needs to be parsed
@@ -594,14 +605,8 @@ def generate_gallery_rst(app):
594605

595606
# generate toctree with subsections
596607
if gallery_conf["nested_sections"] is True:
597-
subsections_toctree = """
598-
.. toctree::
599-
:hidden:
600-
:includehidden:
601-
602-
%s\n
603-
""" % "\n ".join(subsection_index_files)
604-
# """ % "\n ".join(this_toctree_items + subsection_index_files)
608+
subsections_toctree = _format_toctree(
609+
subsection_index_files, includehidden=True)
605610

606611
# add toctree to file only if there are subsections
607612
if len(subsection_index_files) > 0:

‎sphinx_gallery/tests/test_full.py

Copy file name to clipboardExpand all lines: sphinx_gallery/tests/test_full.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# gen_modules + sg_api_usage + doc/index.rst + minigallery.rst
4444
N_OTHER = 9 + 1 + 1 + 1 + 1
4545
N_RST = N_EXAMPLES + N_PASS + N_INDEX + N_EXECUTE + N_OTHER
46-
N_RST = '(%s|%s)' % (N_RST, N_RST - 1) # AppVeyor weirdness
46+
N_RST = '(%s|%s|%s)' % (N_RST, N_RST - 1, N_RST - 2) # AppVeyor weirdness
4747

4848

4949
@pytest.fixture(scope='module')
@@ -180,6 +180,7 @@ def test_junit(sphinx_app, tmpdir):
180180
'plot_numpy_matplotlib.py')
181181
failing_fname = op.join(new_src_dir, '../examples', 'future',
182182
'plot_future_imports_broken.py')
183+
print('Names', passing_fname, failing_fname)
183184
shutil.move(passing_fname, passing_fname + '.temp')
184185
shutil.move(failing_fname, passing_fname)
185186
shutil.move(passing_fname + '.temp', failing_fname)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.