✨ feat(api): add use_site_for_root parameter#426
Merged
gaborbernat merged 2 commits intotox-dev:mainfrom Feb 13, 2026
Merged
Conversation
System daemons and installers running as root should write to system-wide directories (/var/cache, /etc/xdg, etc.) rather than /root/.local/..., but platformdirs had no built-in way to handle this. The new opt-in use_site_for_root parameter redirects user_*_dir calls to their site_*_dir equivalents when running as uid 0 on Unix. XDG user environment variables (XDG_DATA_HOME, etc.) are bypassed during the redirect since they are typically inherited from the calling user via sudo. The parameter is accepted on all platforms but is a no-op outside Unix, following the same pattern as roaming on non-Windows.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Feb 14, 2026
Merges changes from upstream/main including: - use_site_for_root parameter (tox-dev#426) - site_state_dir and site_log_dir APIs (tox-dev#424, tox-dev#425) - user_bin_dir and user_applications_dir APIs (tox-dev#430, tox-dev#432) - Windows environment variable overrides (tox-dev#427, tox-dev#428) - Various bug fixes and improvements Adds missing documentation for use_site_for_root parameter in the Usage Guide, addressing issue tox-dev#433. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Feb 14, 2026
Issue tox-dev#433 reported that the use_site_for_root parameter was missing from the Usage Guide despite being available in the API. This parameter was added in tox-dev#426 but documentation was not included in the usage guide. Added a new section documenting use_site_for_root alongside the other parameters. This helps users discover the feature when they need to configure system services running as root to use system-wide directories instead of root's home directory. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Feb 14, 2026
The use_site_for_root parameter was added in tox-dev#426 but wasn't documented in the Usage Guide. Users had no way to discover this feature when configuring system services running as root that need to use system-wide directories instead of root's home directory. Added a dedicated section documenting use_site_for_root alongside other parameters. The documentation explains the Unix-only behavior, the default value for backwards compatibility, and includes a practical example showing how root processes redirect to site directories. Fixes tox-dev#433
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Feb 14, 2026
The use_site_for_root parameter was added in tox-dev#426 but wasn't documented in the Usage Guide. Users had no way to discover this feature when configuring system services running as root that need to use system-wide directories instead of root's home directory. Added a dedicated section documenting use_site_for_root alongside other parameters. The documentation explains the Unix-only behavior, the default value for backwards compatibility, and includes a practical example showing how root processes redirect to site directories. Fixes tox-dev#433
gaborbernat
added a commit
that referenced
this pull request
Feb 14, 2026
The `use_site_for_root` parameter was added in #426 but wasn't documented in the Usage Guide. 📚 Users had no way to discover this feature when configuring system services running as root that need to use system-wide directories instead of root's home directory. Added a dedicated section in the Usage Guide documenting `use_site_for_root` alongside other parameters like `ensure_exists`, `multipath`, and `roaming`. The documentation explains the Unix-only behavior, the default value for backwards compatibility, and includes a practical example showing how root processes redirect to site directories. Fixes #433
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.
System daemons, package managers, and installers running as root currently get user directories under
/root/.local/..., which is rarely the intended behavior. Callers have to manually detect uid 0 and switch tosite_*_dirthemselves, duplicating logic that belongs in the library. Closes #213.✨ The new
use_site_for_rootconstructor parameter (defaulting toFalse) redirects all sixuser_*_dirproperties to theirsite_*_direquivalents when the process is running as root (uid 0) on Unix. The redirect bypasses XDG user environment variables likeXDG_DATA_HOMEentirely, since those are typically inherited from the calling user viasudoand would defeat the purpose of writing to system-wide paths. The parameter follows the same cross-platform pattern asroaming— accepted everywhere, but only meaningful on Unix.Media directories (
user_documents_dir,user_downloads_dir, etc.) are not redirected because nosite_*counterpart exists for them. The parameter is also exposed on all 12 affected standalone functions (user_data_dir,user_data_path, etc.) for convenience. 🔧 Default behavior is completely unchanged — the feature is strictly opt-in.