Skip to content

Commit

Permalink
font_manager: Gracefully handle the case of there being no config dir.
Browse files Browse the repository at this point in the history
Instead of raising RuntimeError, now avoids reading and writing the font cache.
  • Loading branch information
mgiuca-google committed Apr 16, 2013
1 parent 4987dcd commit 64c797b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/matplotlib/font_manager.py
Expand Up @@ -1312,30 +1312,37 @@ def findfont(prop, fontext='ttf'):

else:
configdir = get_configdir()
if configdir is None:
raise RuntimeError('Could not find a suitable configuration directory')
if sys.version_info[0] >= 3:
_fmcache = os.path.join(configdir, 'fontList.py3k.cache')
if configdir is not None:
if sys.version_info[0] >= 3:
_fmcache = os.path.join(configdir, 'fontList.py3k.cache')
else:
_fmcache = os.path.join(configdir, 'fontList.cache')
else:
_fmcache = os.path.join(configdir, 'fontList.cache')
# Should only happen in a restricted environment (such as Google App
# Engine). Deal with this gracefully by not caching fonts.
_fmcache = None

fontManager = None

def _rebuild():
global fontManager
fontManager = FontManager()
pickle_dump(fontManager, _fmcache)
if _fmcache:
pickle_dump(fontManager, _fmcache)
verbose.report("generated new fontManager")

try:
fontManager = pickle_load(_fmcache)
if (not hasattr(fontManager, '_version') or
fontManager._version != FontManager.__version__):
if _fmcache:
try:
fontManager = pickle_load(_fmcache)
if (not hasattr(fontManager, '_version') or
fontManager._version != FontManager.__version__):
_rebuild()
else:
fontManager.default_size = None
verbose.report("Using fontManager instance from %s" % _fmcache)
except:
_rebuild()
else:
fontManager.default_size = None
verbose.report("Using fontManager instance from %s" % _fmcache)
except:
else:
_rebuild()

def findfont(prop, **kw):
Expand Down

0 comments on commit 64c797b

Please sign in to comment.