Skip to content

Fix ValueError in find_project_root for files on multiple Windows drives (#5379) - #5422

Closed
Prateek99-s wants to merge 2 commits into
psf:mainfrom
Prateek99-s:fix-multidrive-root-5379
Closed

Prateek99-s wants to merge 2 commits into
psf:mainfrom
Prateek99-s:fix-multidrive-root-5379

Conversation

@Prateek99-s

Copy link
Copy Markdown
Contributor

Resolves #5379.

**Description:**
When passing sources located on completely different Windows drives (e.g., `black C:\app\a.py D:\tmp\b.py`), `find_project_root` computes the common parents of all input paths. Because paths on separate Windows drives have no common `Path` parent, the resulting set intersection is empty. Previously, passing this empty intersection to `max()` caused an unhandled `ValueError` crash.

This PR fixes the crash by checking if the intersection is empty before calling `max()`. If there is no common base (as is the

case with files on different drives), it gracefully falls back to using the resolved current working directory (Path.cwd()) as
the base to search for configuration files like pyproject.toml.

**Changes:**
- Updated `src/black/files.py` to handle an empty parent intersection and fallback to `Path.cwd()`.
- Added `test_find_project_root_multiple_drives` regression test in `tests/test_black.py` (skipped on non-Windows platforms).

Prateek99-s added a commit to Prateek99-s/black that referenced this pull request Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

diff-shades results comparing this PR (c7cbeb9) to main (64631f6):

--preview style: no changes

--stable style: no changes


What is this? | Workflow run | diff-shades documentation

@cobaltt7

Copy link
Copy Markdown
Collaborator

I believe the project root is only used for finding a config file. I think the best option is to treat it as no config found, use the default config file, and probably warn that no project root was found and the default config was used. Passing --config with a file path manually should silence the warning, as well as passing --silent.
Alternatively, Black could just error with a clear message. If this route is chosen, passing --config should still allow formatting to continue.

Originally posted by @cobaltt7 in #5379

@Prateek99-s
Prateek99-s force-pushed the fix-multidrive-root-5379 branch from c3a422d to c7cbeb9 Compare September 22, 2026 13:04
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.

find_project_root raises ValueError for sources on different Windows drives

2 participants