Repository navigation
🐛 fix(api): accept use_site_for_root in the media and fonts functions - #686
Merged
gaborbernat merged 3 commits intoNov 4, 2026
Conversation
tox-dev#661 made Unix.user_fonts_dir and the nine media properties ignore the invoking user's XDG_DATA_HOME, XDG_*_DIR and user-dirs.dirs for root with use_site_for_root, and return their default under root's home. The module-level functions never got the parameter, so they can't ask for it: as root with XDG_MUSIC_DIR=/home/alice/Music inherited, Unix(use_site_for_root=True).user_music_dir is ~/Music but platformdirs.user_music_dir() has no way to request that and returns /home/alice/Music. Add a keyword-only use_site_for_root to user_fonts_dir/path and the nine media *_dir and *_path functions and forward it, as tox-dev#537 did for the bin functions.
The Unix class ignores an XDG path with a Windows drive, so on Windows the new test never inherited the value and all 20 cases failed. The shared inherited_media_target fixture had the same gap: its other tests passed on Windows without inheriting anything. The fixture now sets drive-less paths, and the new test reuses it and _MEDIA_DIR_CASES instead of a second table, which also drops the too-many-arguments suppression. The use_site_for_root docs now say the module-level media and fonts functions accept it.
gaborbernat
enabled auto-merge (squash)
November 4, 2026 15:43
gaborbernat
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#661 made
Unix.user_fonts_dirand the nine media properties honouruse_site_for_root: for root they ignore the invoking user'sXDG_DATA_HOME,XDG_*_DIRanduser-dirs.dirsand return their default under root's home. The module-level functions never got the parameter, so code using the function API can't ask for that behaviour.Measured on platformdirs 4.14.3, as root (
geteuidpatched to 0) withPlatformDirsset toUnixand another user's variables inherited:#537 closed this gap for
user_bin_dir/user_bin_path, which is why those takeuse_site_for_roottoday. The fonts and media wrappers were the ones left.Change
A keyword-only
use_site_for_root: bool = Falseon these 20 functions, forwarded toPlatformDirs, with the same docstring lineuser_bin_diruses:user_fonts_dir,user_fonts_pathuser_{documents,downloads,pictures,videos,music,desktop,projects,publicshare,templates}_{dir,path}The default is
False, so existing calls behave the same. Theuse_site_for_rootsection of the parameter reference now says these functions take it.