@@ -424,12 +424,14 @@ def _get_xdg_cache_dir():
424424 return os .environ .get ('XDG_CACHE_HOME' ) or str (Path .home () / ".cache" )
425425
426426
427- def _get_config_or_cache_dir (xdg_base ):
427+ def _get_config_or_cache_dir (xdg_base_getter ):
428428 configdir = os .environ .get ('MPLCONFIGDIR' )
429429 if configdir :
430430 configdir = Path (configdir ).resolve ()
431- elif sys .platform .startswith (('linux' , 'freebsd' )) and xdg_base :
432- configdir = Path (xdg_base , "matplotlib" )
431+ elif sys .platform .startswith (('linux' , 'freebsd' )):
432+ # Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
433+ # as _xdg_base_getter can throw.
434+ configdir = Path (xdg_base_getter (), "matplotlib" )
433435 else :
434436 configdir = Path .home () / ".matplotlib"
435437 try :
@@ -470,7 +472,7 @@ def get_configdir():
470472 4. Else, create a temporary directory, and use it as the configuration
471473 directory.
472474 """
473- return _get_config_or_cache_dir (_get_xdg_config_dir () )
475+ return _get_config_or_cache_dir (_get_xdg_config_dir )
474476
475477
476478@_logged_cached ('CACHEDIR=%s' )
@@ -481,7 +483,7 @@ def get_cachedir():
481483 The procedure used to find the directory is the same as for
482484 _get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead.
483485 """
484- return _get_config_or_cache_dir (_get_xdg_cache_dir () )
486+ return _get_config_or_cache_dir (_get_xdg_cache_dir )
485487
486488
487489@_logged_cached ('matplotlib data path: %s' )
0 commit comments