Skip to content

feat: add strict wheel filename validation - #1309

Open
itscloud0 wants to merge 3 commits into
pypa:mainfrom
itscloud0:fix-873-normalized-wheel-version
Open

feat: add strict wheel filename validation#1309
itscloud0 wants to merge 3 commits into
pypa:mainfrom
itscloud0:fix-873-normalized-wheel-version

Conversation

@itscloud0

@itscloud0 itscloud0 commented Jul 1, 2026

Copy link
Copy Markdown

Summary

Fixes #873.

parse_wheel_filename() remains lenient for legacy wheel consumers. With strict=True, it now validates all three normalized wheel-filename components: the project name in wheel form, the PEP 440 version token, and sorted compressed tag sets.

User outcome

Strict consumers can reject malformed wheel filenames without changing the existing lenient parser behavior for installed legacy artifacts.

Verification

  • uv run --group test pytest tests/test_utils.py -q
  • uvx ruff check src/packaging/utils.py tests/test_utils.py
  • uvx ruff format --check src/packaging/utils.py tests/test_utils.py

Limitations

This opt-in change is scoped to wheel filenames; sdist parsing and the default lenient API remain unchanged.

@notatallshaw notatallshaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As discussed in the issue, the specification changed and there are now two ways the specification says a wheel should be parsed, strictly for tools that don't have to deal with old wheels, and leniently for tools that do. Packaging doesn't know what the context of the caller is.

@itscloud0 itscloud0 changed the title Reject non-normalized wheel filename versions Add strict wheel filename version validation Jul 2, 2026
@itscloud0
itscloud0 marked this pull request as ready for review July 2, 2026 05:12
Comment thread src/packaging/utils.py Outdated

If **validate_order** is true, compressed tag set components are
checked to be in sorted order as required by PEP 425.
If **strict** is true, the version component must already be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why only the version component? The spec says to normalize the name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That reminds me, what about ensuring the tags are sorted, too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tags are sorted

Alphanumerically?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#909 is the discussion I'm remembering.

@itscloud0
itscloud0 force-pushed the fix-873-normalized-wheel-version branch from 3e6503b to 895647d Compare July 20, 2026 05:12
@itscloud0 itscloud0 changed the title Add strict wheel filename version validation Add strict wheel filename validation Jul 20, 2026
@henryiii henryiii changed the title Add strict wheel filename validation feat: add strict wheel filename validation Jul 20, 2026
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.

Bug: parse_wheel_filename permits non-normalized versions.

5 participants