🐛 fix(windows): avoid FileNotFoundError in sandboxed environments#422
Merged
gaborbernat merged 3 commits intotox-dev:mainfrom Feb 13, 2026
Merged
🐛 fix(windows): avoid FileNotFoundError in sandboxed environments#422gaborbernat merged 3 commits intotox-dev:mainfrom
gaborbernat merged 3 commits intotox-dev:mainfrom
Conversation
SHGetKnownFolderPath with default flags (0) verifies that the target folder physically exists, raising FileNotFoundError in sandboxed Windows environments where USERPROFILE points to a directory without AppData\Local. This was a regression introduced in 4.7.0 when PR tox-dev#380 replaced SHGetFolderPathW with SHGetKnownFolderPath. Passing KF_FLAG_DONT_VERIFY (0x00004000) restores the pre-4.7.0 behavior of returning the expected path without existence checks, matching how the old SHGetFolderPathW API worked. Closes tox-dev#421 Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
On Windows, call get_win_folder_via_ctypes with the real Windows API for each CSIDL name to verify integration. Reserve mock-based tests for non-Windows where ctypes Windows bindings don't exist.
Move ctypes.WinDLL mock assignment into _setup_ctypes_mocks so the type: ignore comment only exists in one place that ty can reason about.
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.
platformdirs 4.7.0 throws
FileNotFoundErroron Windows whenUSERPROFILEpoints to a directory withoutAppData\Local. This regression was introduced in #380, which replacedSHGetFolderPathWwithSHGetKnownFolderPath. 🐛 Unlike the old API,SHGetKnownFolderPathverifies folder existence by default and raises when the directory is missing — breaking sandboxed environments, CI containers, and custom user profiles.The fix passes
KF_FLAG_DONT_VERIFY(0x00004000) as thedwFlagsparameter, tellingSHGetKnownFolderPathto return the expected path without checking whether it physically exists. This restores the 4.6.0 behavior while keeping the modern API. The flag is defined as aFinal[int]module constant since CPython doesn't expose Windows SDK known-folder flags.Closes #421