Repository navigation
fix: resolve PUBLIC before looking up the user home - #546
Merged
gaborbernat merged 5 commits intoSep 16, 2026
Merged
Conversation
emme1t
marked this pull request as ready for review
September 12, 2026 06:50
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
user_publicshare_dir and the environment variable fallback resolver checked only for None. PUBLIC="" gave "." and LOCALAPPDATA="" gave ".\Acme\MyApp", both relative to the working directory. The tox-dev#546 PR noted the empty PUBLIC case and left it open. A falsy check sends an empty PUBLIC to the home-based default and makes the fallback resolver raise the same ValueError it raises for an unset variable. The property still reads PUBLIC before touching the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
On Windows, PUBLIC="" made user_publicshare_dir return "." and LOCALAPPDATA="" made the environment variable fallback give ".\Acme\MyApp". Both point at the working directory. The two lookups checked for None only, and the tox-dev#546 PR noted the empty PUBLIC case without fixing it. With a falsy check, user_publicshare_dir falls back to the home-based Public folder, and the fallback resolver raises the ValueError it raises for an unset variable. The property still reads PUBLIC before it touches the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
On Windows, PUBLIC="" made user_publicshare_dir return "." and LOCALAPPDATA="" made the environment variable fallback give ".\Acme\MyApp". Both point at the working directory. The two lookups checked for None only. The tox-dev#546 PR noted the empty PUBLIC case without fixing it. With a falsy check, user_publicshare_dir falls back to the home-based Public folder, and the fallback resolver raises the ValueError it raises for an unset variable. The property keeps reading PUBLIC before it touches the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
On Windows, PUBLIC="" made user_publicshare_dir return "." and LOCALAPPDATA="" made the environment variable fallback give ".\Acme\MyApp". The same fallback turned an empty USERPROFILE or APPDATA into relative media and Start Menu folders such as Documents, and ignored the ALLUSERSPROFILE default when PROGRAMDATA was empty. These lookups checked for a missing variable only. The tox-dev#546 PR noted the empty PUBLIC case without fixing it. Each lookup now treats an empty value as unset. user_publicshare_dir falls back to the home-based Public folder, LOCALAPPDATA raises the ValueError of a missing variable, and USERPROFILE and APPDATA raise the KeyError that os.environ raises when they are unset. An empty PROGRAMDATA falls through to ALLUSERSPROFILE and C:\ProgramData. The property keeps reading PUBLIC before it touches the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
On Windows, PUBLIC="" made user_publicshare_dir return "." and LOCALAPPDATA="" made the environment variable fallback give ".\Acme\MyApp". The same fallback turned an empty USERPROFILE or APPDATA into relative media and Start Menu folders such as Documents, and ignored the ALLUSERSPROFILE default when PROGRAMDATA was empty. These lookups checked for a missing variable only. The tox-dev#546 PR noted the empty PUBLIC case without fixing it. Each lookup treats an empty value as unset. user_publicshare_dir falls back to the home-based Public folder, LOCALAPPDATA raises the ValueError of a missing variable, and USERPROFILE and APPDATA raise the KeyError that os.environ raises when they are unset. An empty PROGRAMDATA falls through to ALLUSERSPROFILE and C:\ProgramData. The property keeps reading PUBLIC before it touches the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
On Windows, PUBLIC="" made user_publicshare_dir return "." and LOCALAPPDATA="" made the environment variable fallback give ".\Acme\MyApp". The same fallback turned an empty USERPROFILE or APPDATA into relative media and Start Menu folders such as Documents, and ignored the ALLUSERSPROFILE default when PROGRAMDATA was empty. These lookups checked for a missing variable only. The tox-dev#546 PR noted the empty PUBLIC case without fixing it. Each lookup treats an empty value as unset. user_publicshare_dir falls back to the home-based Public folder, LOCALAPPDATA raises the ValueError of a missing variable, and USERPROFILE and APPDATA raise the KeyError that os.environ raises when they are unset. An empty PROGRAMDATA falls through to ALLUSERSPROFILE and C:\ProgramData. The property keeps reading PUBLIC before it touches the home directory, so the tox-dev#546 fix holds when Python cannot find the home.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
user_templates_dir and user_bin_dir joined fixed names onto APPDATA and LOCALAPPDATA, and user_publicshare_dir read the PUBLIC variable. Windows lets a user redirect per-user known folders such as FOLDERID_Templates and FOLDERID_UserProgramFiles; after such a move platformdirs kept returning the default location. Qt asks for FOLDERID_Templates and FOLDERID_Public. The three now share the resolver of the other folders, so a matching WIN_PD_OVERRIDE_* variable wins. Without ctypes, the registry answers for Templates. The environment fallback keeps the old joins and reads PUBLIC before the home directory, treating an empty value as unset as tox-dev#546 and tox-dev#571 require.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
user_templates_dir and user_bin_dir joined fixed names onto APPDATA and LOCALAPPDATA, and user_publicshare_dir read the PUBLIC variable. Windows lets a user redirect per-user known folders such as FOLDERID_Templates and FOLDERID_UserProgramFiles; after such a move platformdirs kept returning the default location. Qt asks for FOLDERID_Templates and FOLDERID_Public. The three now share the resolver of the other folders, so a matching WIN_PD_OVERRIDE_* variable wins. Without ctypes, the registry answers for Templates. The environment fallback keeps the old joins and reads PUBLIC before the home directory, treating an empty value as unset as tox-dev#546 and tox-dev#571 require. Four tests restored os.environ in the wrong order and left HOME, USERPROFILE, PUBLIC or APPDATA changed for later tests. On Windows, SHGetKnownFolderPath expanded the leaked USERPROFILE, so the check against the default layout needs a clean environment.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
user_templates_dir and user_bin_dir joined fixed names onto APPDATA and LOCALAPPDATA, and user_publicshare_dir read the PUBLIC variable. Windows lets a user redirect per-user known folders such as FOLDERID_Templates and FOLDERID_UserProgramFiles; after such a move platformdirs kept returning the default location. Qt asks for FOLDERID_Templates and FOLDERID_Public. The three now share the resolver of the other folders, so a matching WIN_PD_OVERRIDE_* variable wins. Without ctypes, the registry answers for Templates. The environment fallback keeps the old joins and reads PUBLIC before the home directory, treating an empty value as unset as tox-dev#546 and tox-dev#571 require. Four tests restored os.environ in the wrong order and left HOME, USERPROFILE, PUBLIC or APPDATA changed for later tests. On Windows, SHGetKnownFolderPath expanded the leaked USERPROFILE, so the check against the default layout needs a clean environment.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
user_templates_dir and user_bin_dir joined fixed names onto APPDATA and LOCALAPPDATA, and user_publicshare_dir read the PUBLIC variable, so platformdirs did not ask Windows for these folders. A user can redirect FOLDERID_Templates and FOLDERID_UserProgramFiles, and after such a move platformdirs kept returning the default location. Qt asks for FOLDERID_Templates and FOLDERID_Public. The three share the resolver of the other folders, so a matching WIN_PD_OVERRIDE_* variable wins. Without ctypes, the registry answers for Templates. The environment fallback keeps the old joins and reads PUBLIC before the home directory, treating an empty value as unset as tox-dev#546 and tox-dev#571 require. Four tests restored os.environ in the wrong order. They left HOME, USERPROFILE, PUBLIC or APPDATA changed for the tests after them, and on Windows SHGetKnownFolderPath expanded the leaked USERPROFILE.
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.
Windows().user_publicshare_dirraisedRuntimeError: Could not determine home directorywhenPUBLICwas set butUSERPROFILEandHOMEPATHwere missing. Python evaluated theos.environ.get()default,Path("~").expanduser(), before the lookup.On
mainthis raisesRuntimeError; with the fix it printsC:\Users\Shared.The home-based fallback now runs only when
PUBLICis unset. An emptyPUBLICstill normalizes to.. Two tests cover an explicitPUBLICwith no home directory, and the fallback withoutPUBLIC; the first fails onmain.tox rpasses on Python 3.12 and 3.13 (1,243 passed, 94 skipped) with 100% diff coverage.Prepared with OpenAI Codex assistance.