Skip to content

fix: write wheel METADATA as UTF-8 - #138

Draft
aiolibsbot wants to merge 1 commit into
bdraco:mainfrom
aiolibsbot:koan/utf8-metadata-write
Draft

fix: write wheel METADATA as UTF-8#138
aiolibsbot wants to merge 1 commit into
bdraco:mainfrom
aiolibsbot:koan/utf8-metadata-write

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented May 17, 2026

Copy link
Copy Markdown

What

Force `encoding="utf-8"` when writing the extracted METADATA file in `WheelFile.from_wheel`.

Why

`Path.write_text(s)` falls back to the locale-default encoding. With `LC_ALL=C` and `PYTHONUTF8=0` (still common in minimal container images and some CI runners), any wheel whose METADATA contains non-ASCII characters — accented author names, em-dashes, curly quotes in descriptions — raises `UnicodeEncodeError` and aborts the entire index build. The wheel spec defines METADATA as UTF-8, so the indexer should write it that way unconditionally.

How

  • `wheel_file.py`: pass `encoding="utf-8"` to `metadata_path.write_text`.
  • Regression test patches `extract_metadata_from_wheel_file` to return a non-ASCII payload, runs `from_wheel`, and asserts the bytes round-trip as UTF-8.

Testing

`pytest tests/` — 15/15 pass.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 25 insertions(+), 2 deletions(-)

Code scan: clean

Tests: failed (command not found)

Branch hygiene: 1 issue(s)

  • Branch is not pushed to remote

Generated by Kōan post-mission quality pipeline

Path.write_text() uses the locale-default encoding when no encoding
is passed. On systems with a non-UTF-8 default (e.g. LC_ALL=C and
PYTHONUTF8=0), a wheel whose METADATA contains non-ASCII characters
(author names, descriptions) raises UnicodeEncodeError and aborts
the indexer.

Force encoding="utf-8" — METADATA is defined as UTF-8 per the wheel
spec, and we already read it as text via dist_meta. Adds a regression
test that round-trips a metadata payload with non-ASCII characters.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant