Skip to content

Commit db50afd

Browse files
committed
replace fnmatch with Path.match
1 parent 731f32e commit db50afd

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@
163163
error will be raised.
164164
165165
plot_exclude_patterns
166-
List of wildcard (fnmatch) patterns to check against to selectively skip
167-
plot directives. If any pattern matches the relative path of the file
166+
List of non-recursive glob-style patterns to check against to selectively
167+
skip plot directives. If any pattern matches the relative path of the file
168168
containing the plot directive, then that plot directive will be skipped.
169+
Matches are computed using :external+python:meth:`pathlib.PurePath.match`.
169170
170171
Notes on how it works
171172
---------------------
@@ -185,7 +186,6 @@
185186
from collections import defaultdict
186187
import contextlib
187188
import doctest
188-
import fnmatch
189189
from io import StringIO
190190
import itertools
191191
import os
@@ -932,7 +932,7 @@ def run(arguments, content, options, state_machine, state, lineno):
932932

933933
# make figures
934934
try:
935-
if any([fnmatch.fnmatch(source_rel_name, pattern) for pattern in
935+
if any([Path(source_rel_name).match(pattern) for pattern in
936936
config.plot_exclude_patterns]):
937937
results = [(code, [])]
938938
else:

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ def plot_file(num, suff=''):
274274
@pytest.mark.parametrize('plot_exclude_patterns', [False, "*index*",
275275
"index*", "ndex*", "?ndex*",
276276
"*nonmatch*",
277-
"*range*", "*range6*",
278-
"*index*,*range*", "*",
279-
"*_range*", "*script*", ""])
277+
"range*", "range6*",
278+
"index*,range*", "*",
279+
"*_range*", "*script*"])
280280
def test_plot_exclude_patterns(tmp_path, plot_exclude_patterns):
281281
# test that modifying plot_exclude_patterns in config leads to skipping files
282282
shutil.copyfile(tinypages / 'conf.py', tmp_path / 'conf.py')
@@ -328,7 +328,7 @@ def test_plot_exclude_patterns(tmp_path, plot_exclude_patterns):
328328
# from the name of the script containing the plotting function), and thus doesn't
329329
# match. ndex* doesn't match because we're not matching substrings, and thus need
330330
# wildcards for missing characters
331-
if plot_exclude_patterns in ["*script*", "*nonmatch*", False, "", "ndex*"]:
331+
if plot_exclude_patterns in ["*script*", "*nonmatch*", False, "ndex*"]:
332332
assert (img_dir / "index-1.png").exists()
333333
assert (img_dir / "range6_range6.png").exists()
334334
assert (img_dir / "range6_range10.png").exists()
@@ -342,19 +342,19 @@ def test_plot_exclude_patterns(tmp_path, plot_exclude_patterns):
342342
assert (img_dir / "range4.png").exists()
343343
# name of the script used by the plot directive in the scripts rst files all match
344344
# this pattern and thus are all skipped
345-
elif plot_exclude_patterns == "*range*":
345+
elif plot_exclude_patterns == "range*":
346346
assert (img_dir / "index-1.png").exists()
347347
assert not (img_dir / "range6_range6.png").exists()
348348
assert not (img_dir / "range6_range10.png").exists()
349349
assert not (img_dir / "range4.png").exists()
350350
# matches the name of one script, but not the other
351-
elif plot_exclude_patterns == "*range6*":
351+
elif plot_exclude_patterns == "range6*":
352352
assert (img_dir / "index-1.png").exists()
353353
assert not (img_dir / "range6_range6.png").exists()
354354
assert not (img_dir / "range6_range10.png").exists()
355355
assert (img_dir / "range4.png").exists()
356356
# matches all relative paths, so no images created.
357-
elif plot_exclude_patterns in ["*index*,*range*", "*"]:
357+
elif plot_exclude_patterns in ["index*,range*", "*"]:
358358
assert not (img_dir / "index-1.png").exists()
359359
assert not (img_dir / "range6_range6.png").exists()
360360
assert not (img_dir / "range6_range10.png").exists()

0 commit comments

Comments
 (0)