Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a19d9c5

Browse files
committed
Warn if a temporary config/cache dir must be created.
Paying the cost of regen'ing the font cache on every import seems a bit silly when one can just set MPLCONFIGDIR to a persistent directory. Moreover the tmpdir approach is brittle against forking; this is fixable but somewhat complex to do.
1 parent db7cd7e commit a19d9c5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/matplotlib/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,6 @@ def get_home():
519519
return None
520520

521521

522-
def _create_tmp_config_or_cache_dir():
523-
"""
524-
If the config or cache directory cannot be created, create a temporary one.
525-
"""
526-
configdir = os.environ['MPLCONFIGDIR'] = (
527-
tempfile.mkdtemp(prefix='matplotlib-'))
528-
atexit.register(shutil.rmtree, configdir)
529-
return configdir
530-
531-
532522
def _get_xdg_config_dir():
533523
"""
534524
Return the XDG configuration directory, according to the `XDG
@@ -562,7 +552,17 @@ def _get_config_or_cache_dir(xdg_base):
562552
else:
563553
if os.access(str(configdir), os.W_OK) and configdir.is_dir():
564554
return str(configdir)
565-
return _create_tmp_config_or_cache_dir()
555+
# If the config or cache directory cannot be created or is not a writable
556+
# directory, create a temporary one.
557+
tmpdir = os.environ["MPLCONFIGDIR"] = \
558+
tempfile.mkdtemp(prefix="matplotlib-")
559+
atexit.register(shutil.rmtree, tmpdir)
560+
_log.warning(
561+
"Matplotlib created a temporary config/cache directory at %s because "
562+
"the default path (%s) is not a writable directory; it is recommended "
563+
"to set the MPLCONFIGDIR environment variable to a writable "
564+
"directory.", configdir, tmpdir)
565+
return tmpdir
566566

567567

568568
@_logged_cached('CONFIGDIR=%s')

0 commit comments

Comments
 (0)