Skip to content

Commit 19cb886

Browse files
committed
sort examples via JSON file, not title
1 parent 593b4dd commit 19cb886

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
},
183183
"backreferences_dir": "generated",
184184
"examples_dirs": "../examples",
185-
"within_subsection_order": "ExampleTitleSortKey",
185+
"within_subsection_order": "mne_bids.utils._example_sorter",
186186
"gallery_dirs": "auto_examples",
187187
"filename_pattern": "^((?!sgskip).)*$",
188188
}

doc/example_order.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
"read_bids_datasets.py",
3+
"convert_mne_sample.py",
4+
"mark_bad_channels.py",
5+
"convert_eeg_to_bids.py",
6+
"convert_group_studies.py",
7+
"rename_brainvision_files.py",
8+
"convert_mri_and_trans.py",
9+
"convert_ieeg_to_bids.py",
10+
"convert_nirs_to_bids.py",
11+
"convert_empty_room.py",
12+
"bidspath.py",
13+
"create_bids_folder.py",
14+
"update_bids_datasets.py",
15+
"anonymize_dataset.py"
16+
]

mne_bids/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
from datetime import date, datetime, timedelta, timezone
1010
from os import path as op
11+
from pathlib import Path
1112

1213
import numpy as np
1314
from mne import pick_types
@@ -518,6 +519,24 @@ def _import_nibabel(why="work with MRI data"):
518519
return nibabel
519520

520521

522+
# better example sorting, without relying on numbers in example titles
523+
with open(Path(__file__).parents[1] / "doc" / "example_order.json") as fid:
524+
EXAMPLE_ORDER = json.load(fid)
525+
526+
527+
def _example_sorter(filename):
528+
"""Sort for MNE-BIDS example filenames in a custom order.
529+
530+
Examples not explicitly listed in `EXAMPLE_ORDER` above will be sorted at the end.
531+
This is here (instead of in `conf.py`) because it needs to be *importable* for it
532+
to work correctly in Sphinx Gallery / maintain serializability of the sphinx gallery
533+
config dict in `conf.py`.
534+
"""
535+
if filename not in EXAMPLE_ORDER:
536+
EXAMPLE_ORDER.append(filename)
537+
return EXAMPLE_ORDER.index(filename)
538+
539+
521540
def warn(
522541
message,
523542
category=RuntimeWarning,

0 commit comments

Comments
 (0)