Skip to content

🐛 fix(api): accept use_site_for_root in the media and fonts functions - #686

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
abhishekcpp007:fix/use-site-for-root-in-media-and-fonts-functions
Nov 4, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
abhishekcpp007:fix/use-site-for-root-in-media-and-fonts-functions

Conversation

@abhishekcpp007

@abhishekcpp007 abhishekcpp007 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

#661 made Unix.user_fonts_dir and the nine media properties honour use_site_for_root: for root they ignore the invoking user's XDG_DATA_HOME, XDG_*_DIR and user-dirs.dirs and 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 (geteuid patched to 0) with PlatformDirs set to Unix and another user's variables inherited:

os.environ["XDG_DATA_HOME"] = "/home/alice/.local/share"
os.environ["XDG_MUSIC_DIR"] = "/home/alice/Music"

Unix(use_site_for_root=True).user_fonts_dir   # ~/.local/share/fonts
Unix(use_site_for_root=True).user_music_dir   # ~/Music
platformdirs.user_fonts_dir()                 # /home/alice/.local/share/fonts, no parameter to change it
platformdirs.user_music_dir()                 # /home/alice/Music

#537 closed this gap for user_bin_dir / user_bin_path, which is why those take use_site_for_root today. The fonts and media wrappers were the ones left.

Change

A keyword-only use_site_for_root: bool = False on these 20 functions, forwarded to PlatformDirs, with the same docstring line user_bin_dir uses:

  • user_fonts_dir, user_fonts_path
  • user_{documents,downloads,pictures,videos,music,desktop,projects,publicshare,templates}_{dir,path}

The default is False, so existing calls behave the same. The use_site_for_root section of the parameter reference now says these functions take it.

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.
abhishekcpp007 and others added 2 commits November 4, 2026 12:00
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 gaborbernat added bug Something isn't working documentation Improvements or additions to documentation labels Nov 4, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) November 4, 2026 15:43
@gaborbernat
gaborbernat merged commit da92c16 into tox-dev:main Nov 4, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants