@@ -408,12 +408,14 @@ def _get_xdg_cache_dir():
408408 return os .environ .get ('XDG_CACHE_HOME' ) or str (Path .home () / ".cache" )
409409
410410
411- def _get_config_or_cache_dir (xdg_base ):
411+ def _get_config_or_cache_dir (xdg_base_getter ):
412412 configdir = os .environ .get ('MPLCONFIGDIR' )
413413 if configdir :
414414 configdir = Path (configdir ).resolve ()
415- elif sys .platform .startswith (('linux' , 'freebsd' )) and xdg_base :
416- configdir = Path (xdg_base , "matplotlib" )
415+ elif sys .platform .startswith (('linux' , 'freebsd' )):
416+ # Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
417+ # as _xdg_base_getter can throw.
418+ configdir = Path (xdg_base_getter (), "matplotlib" )
417419 else :
418420 configdir = Path .home () / ".matplotlib"
419421 try :
@@ -454,7 +456,7 @@ def get_configdir():
454456 4. Else, create a temporary directory, and use it as the configuration
455457 directory.
456458 """
457- return _get_config_or_cache_dir (_get_xdg_config_dir () )
459+ return _get_config_or_cache_dir (_get_xdg_config_dir )
458460
459461
460462@_logged_cached ('CACHEDIR=%s' )
@@ -465,7 +467,7 @@ def get_cachedir():
465467 The procedure used to find the directory is the same as for
466468 _get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead.
467469 """
468- return _get_config_or_cache_dir (_get_xdg_cache_dir () )
470+ return _get_config_or_cache_dir (_get_xdg_cache_dir )
469471
470472
471473@_logged_cached ('matplotlib data path: %s' )
0 commit comments