diff --git a/doc/conf.py b/doc/conf.py index 7c51f2309288..5efaa80e44c6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -84,7 +84,7 @@ def _check_dependencies(): # Import only after checking for dependencies. # gallery_order.py from the sphinxext folder provides the classes that # allow custom ordering of sections and subsections of the gallery -import sphinxext.gallery_order as gallery_order +from sphinxext import gallery_order # The following import is only necessary to monkey patch the signature later on from sphinx_gallery import gen_rst diff --git a/doc/sphinxext/gallery_order.py b/doc/sphinxext/gallery_order.py index 1c1034ec5819..25a3600a3d9b 100644 --- a/doc/sphinxext/gallery_order.py +++ b/doc/sphinxext/gallery_order.py @@ -3,7 +3,7 @@ Paths are relative to the conf.py file. """ -from sphinx_gallery.sorting import ExplicitOrder +from sphinx_gallery.sorting import ExplicitOrder, ExampleTitleSortKey # Gallery sections shall be displayed in the following order. # Non-matching sections are appended. @@ -64,19 +64,12 @@ def __call__(self, item): explicit_subsection_order = [item + ".py" for item in list_all] -class MplExplicitSubOrder: - """For use within the 'within_subsection_order' key.""" - def __init__(self, src_dir): - self.src_dir = src_dir # src_dir is unused here - self.ordered_list = explicit_subsection_order - - def __call__(self, item): - """Return a string determining the sort order.""" - if item in self.ordered_list: - return "{:04d}".format(self.ordered_list.index(item)) +class MplExplicitSubOrder(ExampleTitleSortKey): + def __call__(self, filename): + if filename in explicit_subsection_order: + return "{:04d}".format(explicit_subsection_order.index(filename)) else: - # ensure not explicitly listed items come last. - return "zzz" + item + return "zzz" + super().__call__(filename) # Provide the above classes for use in conf.py