Skip to content

Commit 2ad60d3

Browse files
authored
Merge pull request matplotlib#31850 from meeseeksmachine/auto-backport-of-pr-31831-on-v3.11.x
Backport PR matplotlib#31831 on branch v3.11.x (DOC: Use warnings instead of exceptions in gallery order)
2 parents 9012ea4 + ad521c8 commit 2ad60d3

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)