Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e528a38

Browse filesBrowse files
authored
Merge pull request #28828 from meeseeksmachine/auto-backport-of-pr-28818-on-v3.9.x
Backport PR #28818 on branch v3.9.x (Resolve configdir so that it's not a symlink when is_dir() is called)
2 parents d4fc88d + 791d6c0 commit e528a38
Copy full SHA for e528a38

File tree

Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,35 +518,38 @@ def _get_xdg_cache_dir():
518518
def _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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.