Validate the build tag passed to wheel pack --build-number - #698
Merged
Conversation
`wheel tags --build` runs the value through `parse_build_tag`, but `wheel pack --build-number` splices it straight into the file name. A build tag that does not start with a digit, or that contains `-`, then produces a name that `packaging.utils.parse_wheel_filename` rejects and that `WHEEL_INFO_RE` silently mis-parses. Reuse the existing validator for `--build-number`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #698 +/- ##
=======================================
Coverage 63.45% 63.45%
=======================================
Files 15 15
Lines 1267 1267
=======================================
Hits 804 804
Misses 463 463 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
agronholm
approved these changes
Sep 2, 2026
agronholm
left a comment
Contributor
There was a problem hiding this comment.
Alright, looks sensible. Thanks!
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.
wheel tags --buildruns its value throughparse_build_tag;wheel pack --build-numberdoes not, and splices it straight into the file name (pack.py:109,name_version += "-" + build_number). The sibling--local-versionoption, handled a few lines further down the same function, is fully validated.Measured on
60cfdda, packing a minimaltest-1.0tree:So
packwritesBuild: 1-2intoWHEELandwheel infoon the file it just produced reportsBuild: 1; withfooit reports no build tag at all and readsnone-anyas the platform tag. The filename grammar is{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whlwith the build tag required to start with a digit, so a-cannot occur inside it.The fix is
type=parse_build_tagon thepackargument — the validatortagsalready uses.Ran
pytest tests/: 74 passed. Reverting onlysrc/wheel/_commands/__init__.pytoorigin/mainand keeping the new test gives 72 passed / 2 failed. A narrower variant that checks only the leading digit (the rule_bdist_wheel.py:309applies) still fails the1-2case, so both halves are load-bearing.ruff checkon the two files I touched is clean; the 22 errors ruff 0.16.5 reports repo-wide are identical on an unmodified checkout, so I did not reformat anything.Not fixed here, but measured:
bdist_wheelhas the leading-digit half of the rule and not the-half, andsetup.py bdist_wheel --build-number 1-2producesdemo-1.0-1-2-py3-none-any.whlthe same way. I left it out to keep this small, since it is a behaviour change on a much more used path — happy to add it here or in a separate PR, whichever you prefer.AI assistance: this change was drafted with Claude Opus 5 (
claude-opus-5). Every number above was produced by running the commands locally against this branch.