Skip to content

import pyplot on MacOS without font cache will search entire subtree of current dir #12176

@dsentinel

Description

@dsentinel

Bug report

Bug summary

On import if /Users/lloyd/.matplotlib/fontlist-v300.json does not exist, will scan entire tree of current dir.
Looks like this was a typo, and then a flake commit included "" which pathlib interperetes as .
https://github.com/matplotlib/matplotlib/pull/11963/files#r218979454

Code for reproduction

On a mac installed with conda if ~/.matplotlib/fontlist-v300.json doesn't exist

(mat_bug_py37) moonbase:~ lloyd$ ls -al /Users/lloyd/.matplotlib/fontlist-v300.json
-rw-r--r--  1 lloyd  staff  130027 Sep 19 10:45 /Users/lloyd/.matplotlib/fontlist-v300.json
(mat_bug_py37) moonbase:~ lloyd$ python -c 'from matplotlib import pyplot'
(mat_bug_py37) moonbase:~ lloyd$ rm  /Users/lloyd/.matplotlib/fontlist-v300.json
(mat_bug_py37) moonbase:~ lloyd$ python -c 'from matplotlib import pyplot'

Takes minutes.... ctl-c

^CTraceback (most recent call last):
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1353, in <module>
    fontManager = json_load(_fmcache)
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 888, in json_load
    with open(filename, 'r') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lloyd/.matplotlib/fontlist-v300.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/pyplot.py", line 32, in <module>
    import matplotlib.colorbar
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
    import matplotlib.contour as contour
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/contour.py", line 18, in <module>
    import matplotlib.font_manager as font_manager
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1363, in <module>
    _rebuild()
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1344, in _rebuild
    fontManager = FontManager()
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 978, in __init__
    ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 270, in findSystemFonts
    fontfiles.update(OSXInstalledFonts(fontext=fontext))
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 218, in OSXInstalledFonts
    for directory in directories
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 220, in <listcomp>
    for path in list_fonts(directory, ext)]
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 157, in list_fonts
    for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 156, in <listcomp>
    return [str(path)
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/pathlib.py", line 1344, in is_file
    return S_ISREG(self.stat().st_mode)
  File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/pathlib.py", line 1140, in stat
    return self._accessor.stat(self)
KeyboardInterrupt
^C

Matplotlib version

  • Operating system: OSX 10.10.5
  • Matplotlib version: 3.0.0
  • Python version: 3.6, and 3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions