Repository navigation
🐛 fix(dirs): create media dirs when ensure_exists is set - #560
Merged
gaborbernat merged 2 commits intoSep 25, 2026
Merged
Conversation
Media dirs from XDG_*_DIR and user-dirs.dirs skipped _optionally_create_directory, so ensure_exists=True did not create them or their parents. Fixes tox-dev#558
The macOS test built its XDG value from a Windows tmp_path, which _xdg_dir rejects because it only accepts POSIX absolute paths. All seven Windows jobs failed on it. The test now mocks Path.mkdir with a fixed POSIX path, the same boundary the site directory tests use. The Unix tests covered three of nine media properties and only the created case. They now cover every property with ensure_exists on and off, plus the user-dirs.dirs and default fallbacks, so a wrong variable name or a creation while off fails a test. The changelog fragment moves to the PR number so towncrier links it, and wraps at 120 columns so docstrfmt stops rewriting it in pre-commit.ci. The two media helpers now sit below the properties that call them.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
4.11.13 (tox-dev#560) made ensure_exists create every Unix media directory, platform defaults such as ~/Templates and ~/Projects included. On a headless box that fills the home directory with folders the user never made. Without HOME it creates a literal ~ directory in the working directory. A configured directory that is a dangling symlink to an unmounted drive made the getter raise FileExistsError. tox-dev#558 asked for the directory from XDG_DOCUMENTS_DIR to exist after access. A configured XDG path tells platformdirs where the user wants the directory, so it keeps creating those, whether they come from the environment or from user-dirs.dirs, on Unix and macOS alike. Defaults stay untouched, and a dangling link comes back unchanged as it did before 4.11.13. The ensure_exists docs now list which directories it creates.
darrenhuai
added a commit
to darrenhuai/platformdirs
that referenced
this pull request
Oct 28, 2026
Since tox-dev#560 the user_documents_dir property and the other eight media properties create a directory the user configured through an XDG_*_DIR variable or user-dirs.dirs when ensure_exists is set. The module-level functions for them still took no arguments, so a caller of user_documents_path() had no way to ask for that and got a path that may not exist, while user_data_path(ensure_exists=True) right next to it did create its directory. Give the nine user_*_dir and user_*_path media functions a keyword-only ensure_exists, the way user_bin_dir got use_site_for_root in tox-dev#537. user_fonts_dir stays as it is: the property never creates the fonts directory, so there is nothing to forward. The new test sets each XDG media variable and checks on disk that the directory appears only when the function is asked for it, so a signature that accepts the argument without passing it on fails too.
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.
ensure_existscreatesuser_data_dirand the other app directories on access, but it left the media directories such asuser_documents_diras they were. A path fromXDG_DOCUMENTS_DIRoruser-dirs.dirsdid not exist after the call, althoughdocs/parameters.rstpromised creation on access. #558 reported it. 🐛On Unix the media properties create the directory and its parents when an XDG variable or
user-dirs.dirssets the path. They create the~/Documentsstyle default too. On macOS they create the directory when an XDG variable sets it, and withensure_exists=Falseplatformdirs creates nothing.The first commit is @ekanshul's work from #559, which had maintainer edits disabled. The second commit carries the review fixes, among them the changelog fragment name.
Windows and Android return their media directories without creating them. So does macOS without an XDG variable. #561 narrowed the Unix behaviour to directories the user configured, after the default-directory creation left stray folders in headless home directories.