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

Skip to content

Sort examples by title, not by filename. #14953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 6 additions & 13 deletions doc/sphinxext/gallery_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down