Skip to content

Rely on rglob support rather than os.walk. #10871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/next_api_changes/2018-02-15-AL-deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The following classes, methods, functions, and attributes are deprecated:
- ``Annotation.arrow``,
- ``cbook.GetRealpathAndStat``, ``cbook.Locked``,
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead),
``cbook.unicode_safe``
``cbook.listFiles``, ``cbook.unicode_safe``
- ``container.Container.set_remove_method``,
- ``dates.DateFormatter.strftime_pre_1900``, ``dates.DateFormatter.strftime``,
- ``font_manager.TempCache``,
Expand Down
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/2018-03-23-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``font_manager.list_fonts`` now follows the platform's casefolding semantics
````````````````````````````````````````````````````````````````````````````

i.e., it behaves case-insensitively on Windows only.
11 changes: 4 additions & 7 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,11 @@ def _get_data_path_cached():


def get_py2exe_datafiles():
datapath = get_data_path()
_, tail = os.path.split(datapath)
data_path = Path(get_data_path())
d = {}
for root, _, files in os.walk(datapath):
files = [os.path.join(root, filename) for filename in files]
root = root.replace(tail, 'mpl-data')
root = root[root.index('mpl-data'):]
d[root] = files
for path in filter(Path.is_file, data_path.glob("**/*")):
(d.setdefault(str(path.parent.relative_to(data_path.parent)), [])
.append(str(path)))
return list(d.items())


Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def dedent(s):
return result


@deprecated("3.0")
def listFiles(root, patterns='*', recurse=1, return_folders=0):
"""
Recursively list files
Expand Down
30 changes: 12 additions & 18 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from functools import lru_cache
import json
import os
from pathlib import Path
import subprocess
import sys
from threading import Timer
Expand Down Expand Up @@ -150,12 +151,13 @@ def get_fontext_synonyms(fontext):

def list_fonts(directory, extensions):
"""
Return a list of all fonts matching any of the extensions,
possibly upper-cased, found recursively under the directory.
Return a list of all fonts matching any of the extensions, found
recursively under the directory.
"""
pattern = ';'.join(['*.%s;*.%s' % (ext, ext.upper())
for ext in extensions])
return cbook.listFiles(directory, pattern)
extensions = ["." + ext for ext in extensions]
return [str(path)
for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
if path.suffix in extensions]


def win32FontDirectory():
Expand Down Expand Up @@ -231,21 +233,13 @@ def win32InstalledFonts(directory=None, fontext='ttf'):


def OSXInstalledFonts(directories=None, fontext='ttf'):
"""
Get list of font files on OS X - ignores font suffix by default.
"""
"""Get list of font files on OS X."""
if directories is None:
directories = OSXFontDirectories

fontext = get_fontext_synonyms(fontext)

files = []
for path in directories:
if fontext is None:
files.extend(cbook.listFiles(path, '*'))
else:
files.extend(list_fonts(path, fontext))
return files
return [path
for directory in directories
for ext in get_fontext_synonyms(fontext)
for path in list_fonts(directory, ext)]


@lru_cache()
Expand Down
14 changes: 4 additions & 10 deletions tools/triage_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,10 @@ def find_failing_tests(result_images, source):
Find all of the failing tests by looking for files with
`-failed-diff` at the end of the basename.
"""
entries = []
for root, dirs, files in os.walk(result_images):
for fname in files:
basename, ext = os.path.splitext(fname)
if basename.endswith('-failed-diff'):
path = os.path.join(root, fname)
entry = Entry(path, result_images, source)
entries.append(entry)
entries.sort(key=lambda x: x.name)
return entries
return sorted(
(Entry(path, result_images, source)
for path in Path(result_images).glob("**/*-failed-diff.*")),
key=lambda x: x.name)


def launch(result_images, source):
Expand Down