Skip to content

Commit 4756fa2

Browse files
authored
Merge pull request #22909 from Croadden/main
FIX: skip sub directories when finding fonts on windows
2 parents aa6e797 + e800616 commit 4756fa2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/matplotlib/font_manager.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,16 @@ def list_fonts(directory, extensions):
196196
recursively under the directory.
197197
"""
198198
extensions = ["." + ext for ext in extensions]
199-
return [os.path.join(dirpath, filename)
200-
# os.walk ignores access errors, unlike Path.glob.
201-
for dirpath, _, filenames in os.walk(directory)
202-
for filename in filenames
203-
if Path(filename).suffix.lower() in extensions]
199+
if sys.platform == 'win32' and directory == win32FontDirectory():
200+
return [os.path.join(directory, filename)
201+
for filename in os.listdir(directory)
202+
if os.path.isfile(filename)]
203+
else:
204+
return [os.path.join(dirpath, filename)
205+
# os.walk ignores access errors, unlike Path.glob.
206+
for dirpath, _, filenames in os.walk(directory)
207+
for filename in filenames
208+
if Path(filename).suffix.lower() in extensions]
204209

205210

206211
def win32FontDirectory():

0 commit comments

Comments
 (0)