Skip to content

fix: accept use_site_for_root in the bin functions - #537

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
darrenhuai:fix-user-bin-dir-use-site-for-root
Sep 1, 2026
Merged

fix: accept use_site_for_root in the bin functions#537
gaborbernat merged 3 commits into
tox-dev:mainfrom
darrenhuai:fix-user-bin-dir-use-site-for-root

Conversation

@darrenhuai

Copy link
Copy Markdown
Contributor

Follow-up to the reach gaps closed in #531 and #534, found by checking the rest of the module-level functions against the properties they wrap.

On Unix, the user_bin_dir property redirects root to site_bin_dir when use_site_for_root is set, the same way data/config/cache/state/log/runtime do. Of those seven redirected properties, user_bin_dir was the only one whose module-level function took no arguments, so the redirect was unreachable through the function API:

>>> Unix(use_site_for_root=True).user_bin_dir  # as root
'/usr/local/bin'
>>> platformdirs.user_bin_dir(use_site_for_root=True)
TypeError: user_bin_dir() got an unexpected keyword argument 'use_site_for_root'

This gives user_bin_dir and user_bin_path the one argument that carries behaviour. The other constructor arguments would be dead weight here: no platform scopes its bin directories to the app, and no platform's bin property calls _optionally_create_directory, so appname/version/ensure_exists can't affect the result. The parameter is keyword-only since it has never shipped on these functions, per the reasoning in #534.

The new test runs every _SITE_REDIRECT_CASES entry through the module-level function as well, in both _dir and _path form. Checked it the hard way: reverting __init__.py fails exactly the user_bin_dir case with the original TypeError, and keeping the signature while dropping the forwarding fails on the value. The _path leg exists because my first version only covered _dir and a non-forwarding user_bin_path mutant slipped straight through it.

Testing: full suite on Windows with 3.14, 1072 passed / 94 skipped (baseline 1058/94), ruff and ty clean. Linux and macOS legs unrun here.

user_bin_dir on Unix redirects root to site_bin_dir when use_site_for_root
is set, the same way the data/config/cache/state/log/runtime directories
do. Of those seven redirected properties it was the only one whose
module-level function took no arguments, so the redirect was unreachable
through user_bin_dir() and user_bin_path() - same shape as the
user_preference_dir gap fixed in tox-dev#531. The parameter is keyword-only
since it has never shipped on these functions.

The new test runs every site-redirect case through the module-level
function as well, in both dir and path form, so the next property added
to the redirect list gets this check for free.
@gaborbernat
gaborbernat force-pushed the fix-user-bin-dir-use-site-for-root branch 2 times, most recently from 103dfd7 to 428cb0b Compare September 1, 2026 04:31
_SITE_REDIRECT_CASES listed seven of the eight properties Unix redirects
under use_site_for_root, so user_applications_dir went untested by the
three tests that read the list and by the new one. Breaking that redirect
now fails three cases instead of none. Its expected value interpolates
os.sep, which matches the joined production path on Windows and needs no
os-path-join suppression.

The new test drops the typed dict and the if. It filters the options by
what each signature accepts, and builds the function name with
removesuffix rather than a replace that does nothing for the dir variant.
@gaborbernat
gaborbernat force-pushed the fix-user-bin-dir-use-site-for-root branch from 428cb0b to edbbd9c Compare September 1, 2026 04:34
@gaborbernat
gaborbernat merged commit c22544b into tox-dev:main Sep 1, 2026
36 checks passed
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.

2 participants