Repository navigation
Normalize Windows-style separators in PackagePath - #560
Open
DeviousCardi wants to merge 2 commits into
Open
DeviousCardi wants to merge 2 commits into
DeviousCardi wants to merge 2 commits into
Conversation
The RECORD specification allows backslashes as directory separators on Windows. Normalize them to portable forward slashes when constructing PackagePath so name, parent, suffix, and as_posix() agree on every platform. Fixes python#528.
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.
Fixes #528.
Approach
The RECORD specification permits
\as a directory separator on Windows, whilePackagePathis aPurePosixPathand treated those separators as literal filename characters. That made.name,.parent,.suffix, and.as_posix()differ between platforms for the same RECORD entry.PackagePathnow normalizes\to/during construction, so RECORD paths are interpreted consistently everywhere. POSIX paths are unchanged because they contain no backslashes. The normalization is applied in both__new__and__init__to cover Python 3.11 (parsing in__new__) and 3.12+ (parsing in__init__).Distribution.files()therefore returnsPackagePathobjects whose string andas_posix()forms are portable, while.locate()continues to resolve against the distribution's actual filesystem path.Tests
Added unit coverage for backslash-only, mixed, absolute Windows (drive-letter), and unchanged POSIX paths, plus an integration test asserting
Distribution.files()normalizes RECORD entries.Run with the repository's documented checks:
Result: 160 passed, 1 skipped, 47 subtests passed; ruff format and lint clean.
AI disclosure
This change was prepared with AI assistance and reviewed by a human before submission.