Skip to content

fix: resolve PUBLIC before looking up the user home - #546

Open
emme1t wants to merge 3 commits into
tox-dev:mainfrom
emme1t:fix/public-directory-without-home
Open

fix: resolve PUBLIC before looking up the user home#546
emme1t wants to merge 3 commits into
tox-dev:mainfrom
emme1t:fix/public-directory-without-home

Conversation

@emme1t

@emme1t emme1t commented Sep 12, 2026

Copy link
Copy Markdown

Windows().user_publicshare_dir raises RuntimeError: Could not determine home directory when PUBLIC is set but the home-directory environment variables are unavailable. The default argument to os.environ.get() evaluates Path("~").expanduser() before the environment lookup returns.

Resolve the home-based fallback only when PUBLIC is absent. Existing normalization, fallback paths, and empty-string behavior are preserved. Add regressions for an unavailable home with an explicit public path and for the fallback when PUBLIC is absent, plus a news fragment.

Reproduced on Windows with Python 3.13:

import os
from unittest.mock import patch
from platformdirs.windows import Windows

with patch.dict(os.environ, {"PUBLIC": r"C:\Users\Shared"}, clear=True):
    print(Windows().user_publicshare_dir)

Before the fix this raises RuntimeError; afterward it returns C:\Users\Shared.

Validation:

  • New regression on original source: the explicit-public-path case fails and the fallback case passes.
  • tox r: Python 3.12 and 3.13 each pass 1,243 tests with 94 skips. Other configured interpreters are unavailable locally and skipped by tox.
  • Coverage, documentation, package metadata/build checks, and type checks pass. All changed executable lines have 100% diff coverage; combined local coverage is 94.50%.
  • The full local formatting environment reports pre-existing YAML comment-spacing and changelog-formatting differences. Running the configured pre-commit hooks on the two changed Python files and the news fragment passes. The repository's pre-commit.ci bot subsequently applied the changelog formatting in its own commit, which is retained in this PR.
  • git diff --check passes.

Prepared with OpenAI Codex assistance. The reproduction and checks above were executed locally, and the patch received an independent agent review.

@emme1t
emme1t marked this pull request as ready for review September 12, 2026 06:50
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.

1 participant