Skip to content

Added handling for undetermined home directory - #30454

Merged
timhoffm merged 2 commits into
matplotlib:mainfrom
Logan-Pageler:fix-issue-30449
Aug 22, 2025
Merged

Added handling for undetermined home directory#30454
timhoffm merged 2 commits into
matplotlib:mainfrom
Logan-Pageler:fix-issue-30449

Conversation

@Logan-Pageler

@Logan-Pageler Logan-Pageler commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

PR summary

If the home directory cannot be created/written to, matplotlib defaults to creating a temporary folder for its caching/config. However, previously, if the home directory could not be determined, a RunTimeError was raised. Now, this pr includes code to handle the RunTimeError from Path.home() so that Matplotlib will default to using a temp directory for its cache. It will also throw a warning to describe the issue.

On Windows the following now leads to a temporary cache directory:

import os
os.environ.pop('HOMEPATH', None)
os.environ.pop('USERPROFILE', None)
import matplotlib

On Linux the following now leads to a temporary cache directory, if the user is not a part of the password database:

import os
os.environ.pop('HOME', None)
import matplotlib

closes #30449

PR checklist

Comment thread lib/matplotlib/__init__.py Outdated
Comment thread lib/matplotlib/__init__.py Outdated
@timhoffm

Copy link
Copy Markdown
Member

I took the liberty of adding a comment on the cause of the RuntimeError.

This is ready to be (suqash-)merged after CI pass.

@timhoffm
timhoffm merged commit 5054100 into matplotlib:main Aug 22, 2025
36 of 37 checks passed
@timhoffm

Copy link
Copy Markdown
Member

Thanks @Logan-Pageler! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

@tacaswell tacaswell added this to the v3.11.0 milestone Aug 22, 2025
rokokol added a commit to rokokol/matplotlib that referenced this pull request Aug 28, 2026
The warning announcing the fallback to a temporary cache directory
lost its f-prefix when the message was refactored in matplotlib#30454, so it
prints a literal "{configdir}".  Restore the interpolation, and when
MPLCONFIGDIR is set explicitly, name the variable instead of blaming
"the default path" the user never touched.

Strengthen test_tmpconfigdir_warning to assert that the resolved path
appears in the warning; the strengthened test fails on the unfixed
code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Config directory location finder doesn't account for the home directory being undetermined.

4 participants