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

Skip to content

Commit 6b8c641

Browse files
Sort gallery subsections by explicit list then by filename
1 parent 126113f commit 6b8c641

File tree

4 files changed

+89
-27
lines changed

4 files changed

+89
-27
lines changed

doc-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ ipython
1212
ipywidgets
1313
numpydoc>=0.4
1414
pillow
15-
sphinx-gallery>=0.1.12
15+
sphinx-gallery>=0.1.13

doc/conf.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# All configuration values have a default value; values that are commented out
1010
# serve to show the default value.
1111

12-
from glob import glob
1312
import os
1413
import shutil
1514
import sys
@@ -72,7 +71,7 @@ def _check_deps():
7271
_check_deps()
7372

7473
# Import only after checking for dependencies.
75-
from sphinx_gallery.sorting import ExplicitOrder
74+
import sphinxext.gallery_order as gallery_order
7675
# This is only necessary to monkey patch the signature later on.
7776
from sphinx_gallery import gen_rst
7877

@@ -94,27 +93,7 @@ def _check_deps():
9493
'cycler': ('https://matplotlib.org/cycler', None),
9594
}
9695

97-
explicit_order_folders = [
98-
'../examples/api',
99-
'../examples/pyplots',
100-
'../examples/subplots_axes_and_figures',
101-
'../examples/color',
102-
'../examples/statistics',
103-
'../examples/lines_bars_and_markers',
104-
'../examples/images_contours_and_fields',
105-
'../examples/shapes_and_collections',
106-
'../examples/text_labels_and_annotations',
107-
'../examples/pie_and_polar_charts',
108-
'../examples/style_sheets',
109-
'../examples/axes_grid',
110-
'../examples/showcase',
111-
'../tutorials/introductory',
112-
'../tutorials/intermediate',
113-
'../tutorials/advanced']
114-
for folder in sorted(glob('../examples/*') + glob('../tutorials/*')):
115-
if not os.path.isdir(folder) or folder in explicit_order_folders:
116-
continue
117-
explicit_order_folders.append(folder)
96+
11897

11998
# Sphinx gallery configuration
12099
sphinx_gallery_conf = {
@@ -128,7 +107,8 @@ def _check_deps():
128107
'scipy': 'https://docs.scipy.org/doc/scipy/reference',
129108
},
130109
'backreferences_dir': 'api/_as_gen',
131-
'subsection_order': ExplicitOrder(explicit_order_folders),
110+
'subsection_order': gallery_order.sectionorder,
111+
'within_subsection_order': gallery_order.subsectionorder,
132112
'min_reported_time': 1,
133113
}
134114

doc/devel/documenting_mpl.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ using the Sphinx_ documentation generation tool. There are several extra
4242
requirements that are needed to build the documentation. They are listed in
4343
:file:`doc-requirements.txt` and listed below:
4444

45-
* Sphinx>=1.3, !=1.5.0, !=1.6.4
45+
* Sphinx>=1.3, !=1.5.0, !=1.6.4, !=1.7.3
4646
* colorspacious
4747
* IPython
4848
* numpydoc>=0.4
4949
* Pillow
50-
* sphinx-gallery>=0.1.12
50+
* sphinx-gallery>=0.1.13
5151
* graphviz
5252

5353
.. note::

doc/sphinxext/gallery_order.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""
2+
Configuration for the order of gallery sections and examples.
3+
Paths are relative to the conf.py file.
4+
5+
"""
6+
7+
from sphinx_gallery.sorting import ExplicitOrder
8+
9+
# Gallery sections shall be diplayed in the following order.
10+
# Non-matching sections are appended.
11+
explicit_order_folders = [
12+
'../examples/api',
13+
'../examples/pyplots',
14+
'../examples/subplots_axes_and_figures',
15+
'../examples/color',
16+
'../examples/statistics',
17+
'../examples/lines_bars_and_markers',
18+
'../examples/images_contours_and_fields',
19+
'../examples/shapes_and_collections',
20+
'../examples/text_labels_and_annotations',
21+
'../examples/pie_and_polar_charts',
22+
'../examples/style_sheets',
23+
'../examples/axes_grid1',
24+
'../examples/axisartist',
25+
'../examples/showcase',
26+
'../tutorials/introductory',
27+
'../tutorials/intermediate',
28+
'../tutorials/advanced']
29+
30+
31+
class MplExplicitOrder(ExplicitOrder):
32+
""" for use within the 'subsection_order' key"""
33+
def __call__(self, item):
34+
if item in self.ordered_list:
35+
return "{:04d}".format(self.ordered_list.index(item))
36+
else:
37+
return "zzz" + item
38+
39+
40+
# Subsection order:
41+
# Subsections are ordered by filename, unless they appear in the following
42+
# lists in which case the list order determines the order within the section.
43+
# Examples/tutorials that do not appear in a list will be appended.
44+
45+
# Tutorials:
46+
list_introductory = ["usage", "pyplot", "sample_plots", "images", "lifecycle",
47+
"customizing"]
48+
list_intermediate = ["artists", "legend_guide", "color_cycle", "gridspec",
49+
"constrainedlayout_guide", "tight_layout_guide"]
50+
list_advanced = []
51+
list_text = ["text_intro", "text_props"]
52+
list_colors = ["colors"]
53+
54+
list_tutorials = list_introductory + list_intermediate + list_advanced + \
55+
list_text + list_colors
56+
57+
# Examples:
58+
list_color = ["color_demo"]
59+
list_pies = ["pie_features", "pie_demo2"]
60+
list_examples = list_color + list_pies
61+
62+
# All items:
63+
list_all = list_tutorials + list_examples
64+
list_all = [item + ".py" for item in list_all]
65+
66+
67+
class MplExplicitSubOrder(object):
68+
""" for use within the 'within_subsection_order' key """
69+
def __init__(self, src_dir):
70+
self.src_dir = src_dir #src_dir is unused here
71+
self.ordered_list = list_all
72+
73+
def __call__(self, item):
74+
if item in self.ordered_list:
75+
return "{:04d}".format(self.ordered_list.index(item))
76+
else:
77+
return "zzz" + item
78+
79+
80+
# Provide the above classes for use in conf.py
81+
sectionorder = MplExplicitOrder(explicit_order_folders)
82+
subsectionorder = MplExplicitSubOrder

0 commit comments

Comments
 (0)