Skip to content

Commit e04a9fa

Browse files
committed
DOC: Use warnings instead of exceptions in gallery order
Exceptions cause a hard exit of sphinx, which is undesirable. Incorrect order specification should not break the build. It also make fixes harder since one one gets the first ordering issue and possibly would have to do multiple builds to see and fix multiple ordering issues.
1 parent 979c178 commit e04a9fa

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

doc/sphinxext/gallery_order.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from pathlib import Path
88

99
from sphinx_gallery.sorting import ExplicitOrder
10+
from sphinx.util import logging as sphinx_logging
11+
12+
logger = sphinx_logging.getLogger(__name__)
1013

1114
# Gallery sections shall be displayed in the following order.
1215
# Non-matching sections are inserted at the unsorted position
@@ -98,7 +101,7 @@ class MplFileExplicitOrder(ExplicitOrder):
98101
Use this if you want to ensure that a full order is intentionally maintained.
99102
"""
100103
def __init__(self, src_dir):
101-
ordered_list = self.read_gallery_order(Path(src_dir)) or []
104+
ordered_list = self.read_gallery_order(Path(src_dir).resolve()) or []
102105
super().__init__(ordered_list)
103106

104107
@staticmethod
@@ -135,13 +138,14 @@ def read_gallery_order(src_dir: Path):
135138
non_existing_examples = listed_examples - existing_examples
136139
missing_examples = existing_examples - listed_examples
137140

141+
rel_txt_path = gallery_order_txt.relative_to(gallery_order_txt.parents[3])
138142
if non_existing_examples:
139-
raise ValueError(
140-
f"The following examples listed in {gallery_order_txt} do not exist: "
143+
logger.warning(
144+
f"The following examples listed in {rel_txt_path} do not exist: "
141145
f"{', '.join(non_existing_examples)}")
142146
if placeholder_index is None and missing_examples:
143-
raise ValueError(
144-
f"The following examples are not listed in {gallery_order_txt}. "
147+
logger.warning(
148+
f"The following examples are not listed in {rel_txt_path}. "
145149
f"Either include them or add a '*' to indicate where not listed "
146150
f"examples should be placed: "
147151
f"{', '.join(missing_examples)}"

0 commit comments

Comments
 (0)