Skip to content

fix(windows): raise when no home directory resolves - #627

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
XXXXXQ-0206:fix-windows-projects-unknown-home
Oct 17, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
XXXXXQ-0206:fix-windows-projects-unknown-home

Conversation

@XXXXXQ-0206

Copy link
Copy Markdown
Contributor

On Windows, user_projects_dir returns a literal ~\Projects when no home directory resolves instead of raising: it is the last ~ default in the package still resolved with the raw helper, and os.path.expanduser leaves the tilde in place when the home is unknown (only Path.expanduser raises).

Contract: the rule already exists elsewhere in the same package. _xdg._expand_user documents that it raises RuntimeError "if neither HOME nor the password database gives a home directory", and api._ensure_home_known refuses a path that still starts with ~ because "creating it would make a ~ directory in the cwd". #578 and #589 applied that rule to the Unix and macOS directories, and #624 to the iOS ones; Windows is the last module still resolving ~ with the raw helper.

Fix: route ~/Projects through _expand_user, as unix.py, macos.py and ios.py already do. One line; the outer os.path.normpath stays because the helper joins with forward slashes.

Tests: a new case patches os.path.expanduser to leave the tilde and asserts RuntimeError; it fails without the change (DID NOT RAISE) and passes with it. The existing expectation that ~/Projects equals Path("~/Projects").expanduser() when a home exists is unchanged. tests/test_windows.py: 201 passed, 20 skipped; full suite: 2025 passed, 350 skipped.

Not covered: the new case mocks the home lookup seam, so it does not run in a real Windows session without a home; the genuinely unresolvable-home path is what the shared helper is tested for on the other platforms. docs/parameters.rst still describes the home-directory source for Unix and macOS only.

user_projects_dir was the last directory that called os.path.expanduser directly, which leaves the tilde in place when the home is unknown, so it returned a literal ~\\Projects. Route it through _expand_user like the unix, macOS and iOS directories already do, and cover the unknown-home case.
@XXXXXQ-0206
XXXXXQ-0206 force-pushed the fix-windows-projects-unknown-home branch from d511454 to 715200e Compare October 17, 2026 19:19
@XXXXXQ-0206
XXXXXQ-0206 marked this pull request as ready for review October 17, 2026 19:21
Copilot AI balanced review requested due to automatic review settings October 17, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gaborbernat
gaborbernat enabled auto-merge (squash) October 17, 2026 19:24
@gaborbernat
gaborbernat merged commit 9b5c0fd into tox-dev:main Oct 17, 2026
33 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.

3 participants