fix long path issue on Windows#10794
Merged
radoering merged 1 commit intopython-poetry:mainfrom Mar 29, 2026
Merged
Conversation
Reviewer's GuideIntroduces a compatibility helper for Path.is_relative_to that normalizes Windows long path prefixes and replaces direct Path.is_relative_to calls with this helper across the codebase, adding tests to verify behavior on POSIX and Windows paths (including long-path and UNC variants) and improving error diagnostics when wheel files attempt to write outside their installation target directory. Sequence diagram for wheel_installer.write_to_fs path safety check with is_relative_tosequenceDiagram
participant WheelInstaller
participant SchemeDict as scheme_dict
participant Compat as _compat
participant TargetDir as target_dir
participant TargetPath as target_path
WheelInstaller->>SchemeDict: lookup scheme
SchemeDict-->>WheelInstaller: scheme_path
WheelInstaller->>TargetDir: Path(scheme_path).resolve()
WheelInstaller->>TargetPath: (target_dir / path).resolve()
WheelInstaller->>Compat: is_relative_to(target_path, target_dir)
Compat-->>WheelInstaller: is_relative
alt target_path not relative to target_dir
WheelInstaller-->>WheelInstaller: raise ValueError with path, target_dir, target_path
else target_path inside target_dir
WheelInstaller-->>WheelInstaller: proceed to write file
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/utils/test_compat.py" line_range="12-26" />
<code_context>
+from poetry.utils._compat import is_relative_to
+
+
+@pytest.mark.parametrize(
+ ("path1", "path2", "expected"),
+ [
+ ("a", "a", True),
+ ("a/b", "a/b", True),
+ ("a/b", "a", True),
+ ("a", "a/b", False),
+ ("a/b/c/d", "a/b", True),
+ ("a/b", "a/b/c/d", False),
+ ],
+)
+def test_is_relative_to(path1: str, path2: str, expected: bool) -> None:
+ assert is_relative_to(Path(path1), Path(path2)) is expected
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add Windows tests for paths on different drives / different UNC servers to avoid false positives
Current Windows parametrization only covers cases where `path1` and `path2` are on the same drive/server. To guard against false positives from the prefix-stripping logic, please add negative cases where roots differ, e.g.:
- `path1=r"C:\a\b"`, `path2=r"D:\a"` → `False`
- `path1=r"\\?\C:\a\b"`, `path2=r"D:\"` → `False`
- `path1=r"\\?\UNC\server1\a\b"`, `path2=r"\\?\UNC\server2\a"` → `False`
- `path1=r"\\server1\a\b"`, `path2=r"\\?\UNC\server2\a"` → `False`
These will help ensure unrelated roots are never treated as parents after prefix removal.
```suggestion
@pytest.mark.parametrize(
("path1", "path2", "expected"),
[
("a", "a", True),
("a/b", "a/b", True),
("a/b", "a", True),
("a", "a/b", False),
("a/b/c/d", "a/b", True),
("a/b", "a/b/c/d", False),
],
)
def test_is_relative_to(path1: str, path2: str, expected: bool) -> None:
assert is_relative_to(Path(path1), Path(path2)) is expected
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific path semantics")
@pytest.mark.parametrize(
("path1", "path2", "expected"),
[
("C:\\a\\b", "D:\\a", False),
("\\\\?\\C:\\a\\b", "D:\\", False),
("\\\\?\\UNC\\server1\\a\\b", "\\\\?\\UNC\\server2\\a", False),
("\\\\server1\\a\\b", "\\\\?\\UNC\\server2\\a", False),
],
)
def test_is_relative_to_windows_different_roots(
path1: str, path2: str, expected: bool
) -> None:
assert is_relative_to(Path(path1), Path(path2)) is expected
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
0b9e540 to
2d47912
Compare
2d47912 to
ba4b185
Compare
radoering
added a commit
that referenced
this pull request
Mar 29, 2026
(cherry picked from commit a16fbb1)
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.
Pull Request Check List
#10792 introduced an issue with long paths on Windows that causes sporadic test failures that look like:
This change works around this issue. To be consistent, I replaced all uses of
Path.is_relative_to()with the method that works around the issue.Summary by Sourcery
Add a cross-platform path relativity helper and adopt it to avoid Windows long-path issues.
Bug Fixes:
Enhancements:
Tests: