Skip to content

Added parsing function to gallery_order.py to categorize folders in galleries directory as sorted or unsorted #27442

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 5 commits 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
56 changes: 56 additions & 0 deletions doc/sphinxext/gallery_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from sphinx_gallery.sorting import ExplicitOrder
import os

# Gallery sections shall be displayed in the following order.
# Non-matching sections are inserted at the unsorted position
Expand Down Expand Up @@ -123,3 +124,58 @@ def __call__(self, item):
# Provide the above classes for use in conf.py
sectionorder = MplExplicitOrder(explicit_order_folders)
subsectionorder = MplExplicitSubOrder

# README file types
READMES_FILES = ["README.txt"] # , "README.rst"]
ORDER_TYPE = {"examples": "example",
"tutorials": "tutorial",
"plot_types": "plot"}


def parse_readme(file_to_read, order_type):
file = open(file_to_read)
for line in file:
if line.find(ORDER_TYPE[order_type]) != -1:
return True

return False


DIRECTORIES = ["examples", "tutorials",
"plot_types"]


def follow_directory():
new_folder_list = []
for parent_folder in DIRECTORIES:
directory_list = [UNSORTED]
parent_folder_path = "galleries/" + parent_folder
items = os.listdir(parent_folder_path)
folders = [item for item in items
if os.path.isdir(os.path.join(parent_folder_path, item))]

for folder in folders:
folder_to_parse = parent_folder_path + "/" + folder + "/"
file_to_parse = None
if os.path.exists(folder_to_parse + "README.txt"):
file_to_parse = folder_to_parse + "README.txt"
elif os.path.exists(folder_to_parse + "README.rst"):
file_to_parse = folder_to_parse + "README.rst"

file_type = parse_readme(file_to_parse, parent_folder)

if file_type:
directory_list = [folder_to_parse] + directory_list
else:
directory_list.append(folder_to_parse)

new_folder_list.append(directory_list)

print(folder_lists)
print("-------------------------")
print(new_folder_list)

return new_folder_list
# folder_lists = new_folder_list

follow_directory()
19 changes: 19 additions & 0 deletions galleries/gallery_order.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
['galleries/examples/user_interfaces/', 'galleries/examples/units/',
'galleries/examples/ticks/', 'galleries/examples/subplots_axes_and_figures/',
'galleries/examples/style_sheets/', 'galleries/examples/statistics/', 'galleries/examples/spines/',
'galleries/examples/specialty_plots/', 'galleries/examples/showcase/', 'galleries/examples/shapes_and_collections/',
'galleries/examples/scales/', 'galleries/examples/pyplots/', 'galleries/examples/mplot3d/', 'galleries/examples/misc/',
'galleries/examples/lines_bars_and_markers/', 'galleries/examples/images_contours_and_fields/',
'galleries/examples/event_handling/', 'galleries/examples/color/', 'galleries/examples/axisartist/',
'galleries/examples/axes_grid1/', 'galleries/examples/animation/',
'unsorted',
'galleries/examples/pie_and_polar_charts/', 'galleries/examples/text_labels_and_annotations/',
'galleries/examples/userdemo/', 'galleries/examples/widgets/'
],
['unsorted'],
['galleries/plot_types/unstructured/', 'galleries/plot_types/stats/',
'galleries/plot_types/basic/', 'galleries/plot_types/arrays/', 'galleries/plot_types/3D/',
'unsorted'
]
]