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

Resolve configdir so that it's not a symlink when is_dir() is called #28818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

hintron
Copy link
Contributor

@hintron hintron commented Sep 13, 2024

Closes #28817.

There are some use cases where a user might have to make ~/.config a symlink (e.g. if a corporate home directory has limited space, and symlinks are used to offload the storage to a separate storage disk). So resolving configdir beforehand should prevent the is_dir() check from failing, causing a warning to be issued and forcing a temporary directory to be used.

PR summary

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@hintron
Copy link
Contributor Author

hintron commented Sep 13, 2024

Quick description of the patch:

If you look at this code, only one of the three code paths here resolves their paths before assigning to configdir:

if configdir:
configdir = Path(configdir).resolve()
elif sys.platform.startswith(('linux', 'freebsd')):
# Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
# as _xdg_base_getter can throw.
configdir = Path(xdg_base_getter(), "matplotlib")
else:
configdir = Path.home() / ".matplotlib"

All three of those paths should resolve before assigning, so no symlinks are left over and the is_dir() check always works as intended (because a symlink is not a dir) EDIT: is_symlink() and is_dir() can both be true for a symlink:

if os.access(str(configdir), os.W_OK) and configdir.is_dir():
return str(configdir)

@hintron hintron marked this pull request as ready for review September 13, 2024 22:42
Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. Minor suggestion to add a note on why this is there so we don't remove it accidentally in the future, and possibly just do it once right before it is needed.

lib/matplotlib/__init__.py Outdated Show resolved Hide resolved
There are some use cases where a user might have a symlinked home directory
(e.g. a corporate home directory may be symlinked to a disk with limited
space, and is only accessible to other users via a real path to the
underlying disk).
Resolving configdir before any mkdir or access checks should avoid this
problem.

Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
@hintron hintron force-pushed the 28817-v1 branch 2 times, most recently from 89d18d8 to a8ce9b5 Compare September 14, 2024 06:57
@hintron hintron marked this pull request as ready for review September 14, 2024 07:04
@hintron
Copy link
Contributor Author

hintron commented Sep 14, 2024

Ok, I realized my thinking about the original problem was off (see #28817 (comment)), but the solution of forcing a resolve() is still the same. I just tweaked the comment a bit in commit 957271f.

In commit 8837d9a, I add a missing error check, and then print two different warnings depending on what actually failed. This should help narrow down what is going on instead of e.g. seeing "path is not a writable directory" when in reality the path was inaccessible or the disk was full.

For example, a user could have no more disk space, causing mkdir to fail,
but not realize it because the error is silently discarded, and the
subsequent warning would not indicate the actual issue.
@tacaswell tacaswell added this to the v3.9.3 milestone Sep 16, 2024
@tacaswell tacaswell merged commit 1b08207 into matplotlib:main Sep 16, 2024
47 checks passed
@tacaswell
Copy link
Member

Thank you @hintron and congratulations on your first merged Matplotlib PR 🎉 I hope we hear from you agian.

@hintron
Copy link
Contributor Author

hintron commented Sep 16, 2024

@tacaswell Shouldn't commit 1b08207 show me as the author and you as the committer? Or does the matplotlib project not do it that way?

@hintron
Copy link
Contributor Author

hintron commented Sep 16, 2024

Oh, nevermind, that's just the merge commit, not a squashed rebase commit. Carry on :)

QuLogic added a commit that referenced this pull request Sep 17, 2024
…818-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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Bug]: ~/.config/matplotlib is never used because ~/.config is a symlink
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.