Skip to content

Validate the build tag passed to wheel pack --build-number - #698

Merged
agronholm merged 1 commit into
pypa:mainfrom
dylanpulver:validate-pack-build-number
Sep 2, 2026
Merged

Validate the build tag passed to wheel pack --build-number#698
agronholm merged 1 commit into
pypa:mainfrom
dylanpulver:validate-pack-build-number

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

wheel tags --build runs its value through parse_build_tag; wheel pack --build-number does not, and splices it straight into the file name (pack.py:109, name_version += "-" + build_number). The sibling --local-version option, handled a few lines further down the same function, is fully validated.

Measured on 60cfdda, packing a minimal test-1.0 tree:

--build-number foo  ->  test-1.0-foo-py3-none-any.whl
    wheel's own WHEEL_INFO_RE : build=None, pyver='foo', abi='py3', plat='none-any'
    packaging 26.3            : InvalidWheelFilename: Invalid build number: foo

--build-number 1-2  ->  test-1.0-1-2-py3-none-any.whl
    wheel's own WHEEL_INFO_RE : build='1', pyver='2', abi='py3', plat='none-any'
    packaging 26.3            : InvalidWheelFilename: wrong number of parts

So pack writes Build: 1-2 into WHEEL and wheel info on the file it just produced reports Build: 1; with foo it reports no build tag at all and reads none-any as the platform tag. The filename grammar is {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl with the build tag required to start with a digit, so a - cannot occur inside it.

The fix is type=parse_build_tag on the pack argument — the validator tags already uses.

Ran pytest tests/: 74 passed. Reverting only src/wheel/_commands/__init__.py to origin/main and keeping the new test gives 72 passed / 2 failed. A narrower variant that checks only the leading digit (the rule _bdist_wheel.py:309 applies) still fails the 1-2 case, so both halves are load-bearing. ruff check on 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_wheel has the leading-digit half of the rule and not the - half, and setup.py bdist_wheel --build-number 1-2 produces demo-1.0-1-2-py3-none-any.whl the 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.

`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

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.45%. Comparing base (60cfdda) to head (f3624f2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@agronholm agronholm left a comment

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.

Alright, looks sensible. Thanks!

@agronholm
agronholm merged commit b25c3c2 into pypa:main Sep 2, 2026
16 checks passed
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.

2 participants