Validate license files are valid UTF-8 text in bdist_wheel - #5310
Open
CAOShurong wants to merge 1 commit into
Open
Validate license files are valid UTF-8 text in bdist_wheel#5310CAOShurong wants to merge 1 commit into
CAOShurong wants to merge 1 commit into
Conversation
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Per PEP 639, tools MUST assume license file content is UTF-8 and SHOULD validate this. Previously binary files matched by license-files glob patterns (e.g. LICENSE.pdf via the default LICEN[CS]E* pattern) were silently copied into the wheel's dist-info/licenses directory. Raise InvalidConfigError from bdist_wheel's egg2dist when any bundled license file fails UTF-8 decoding. Fixes pypa#4936 Signed-off-by: Shurong Cao <170531907+CAOShurong@users.noreply.github.com>
CAOShurong
force-pushed
the
codex/4936-license-files-utf8
branch
from
August 24, 2026 09:13
8a84894 to
df1ee4a
Compare
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 #4936
Problem
PEP 639 requires tools to assume license file content is valid UTF-8 encoded text, and states that tools SHOULD validate this and raise an error if it is not.
setuptoolscurrently copies whatever files match thelicense-filespatterns — including binary files likeBadLicense.doc,LICENSE.pdfor even a straylicense.pymatched by the default globs (LICEN[CS]E*) — straight into.dist-info/licenses/with no warning or error (issue #4936).Fix
Add
_validate_license_file_encoding()insetuptools/command/bdist_wheel.py. It runs for every license file just before it is copied into the wheel'slicenses/folder (inegg2dist), and raisesInvalidConfigErrorwhen UTF-8 decoding fails:Because the validation lives in
bdist_wheel's copy loop, it covers both explicit patterns and the default globs, on every platform, regardless of how the file list was resolved.Verification (all on real Windows 11)
test_binary_license_file_raises: fails onmain(binary file silently bundled), passes with this change — RED/GREEN proven.setuptools/tests/test_bdist_wheel.py: 29 passed, 2 skipped (unchanged from baseline).test_wheel.py+config/suites: 204 passed, 1 xfailed (unchanged).ruff check+ruff format --checkclean;mypy setuptools/command/bdist_wheel.py: no issues.setuptools.build_meta.build_wheel():license.pdfcontaining invalid UTF-8 bytes + default globs → build now fails with the error above (previously succeeded and shipped the binary).LICENSE.txt→ wheel builds normally, license entries present in.dist-info/licenses/.Notes for reviewers
SetuptoolsWarningwith a deprecation-style due date) I'm happy to convert this — the mechanism would stay identical, only the raise becomes an emit.DCO sign-off included in the commit.