@@ -518,35 +518,38 @@ def _get_xdg_cache_dir():
518518def _get_config_or_cache_dir (xdg_base_getter ):
519519 configdir = os .environ .get ('MPLCONFIGDIR' )
520520 if configdir :
521- configdir = Path (configdir ). resolve ()
521+ configdir = Path (configdir )
522522 elif sys .platform .startswith (('linux' , 'freebsd' )):
523523 # Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
524524 # as _xdg_base_getter can throw.
525525 configdir = Path (xdg_base_getter (), "matplotlib" )
526526 else :
527527 configdir = Path .home () / ".matplotlib"
528+ # Resolve the path to handle potential issues with inaccessible symlinks.
529+ configdir = configdir .resolve ()
528530 try :
529531 configdir .mkdir (parents = True , exist_ok = True )
530- except OSError :
531- pass
532+ except OSError as exc :
533+ _log . warning ( "mkdir -p failed for path %s: %s" , configdir , exc )
532534 else :
533535 if os .access (str (configdir ), os .W_OK ) and configdir .is_dir ():
534536 return str (configdir )
537+ _log .warning ("%s is not a writable directory" , configdir )
535538 # If the config or cache directory cannot be created or is not a writable
536539 # directory, create a temporary one.
537540 try :
538541 tmpdir = tempfile .mkdtemp (prefix = "matplotlib-" )
539542 except OSError as exc :
540543 raise OSError (
541- f"Matplotlib requires access to a writable cache directory, but the "
542- f"default path ({ configdir } ) is not a writable directory , and a temporary "
544+ f"Matplotlib requires access to a writable cache directory, but there "
545+ f"was an issue with the default path ({ configdir } ), and a temporary "
543546 f"directory could not be created; set the MPLCONFIGDIR environment "
544547 f"variable to a writable directory" ) from exc
545548 os .environ ["MPLCONFIGDIR" ] = tmpdir
546549 atexit .register (shutil .rmtree , tmpdir )
547550 _log .warning (
548- "Matplotlib created a temporary cache directory at %s because the default path "
549- "(%s) is not a writable directory ; it is highly recommended to set the "
551+ "Matplotlib created a temporary cache directory at %s because there was "
552+ "an issue with the default path (%s) ; it is highly recommended to set the "
550553 "MPLCONFIGDIR environment variable to a writable directory, in particular to "
551554 "speed up the import of Matplotlib and to better support multiprocessing." ,
552555 tmpdir , configdir )
0 commit comments