setuptoolsで作ったwheelをPyPIにアップロードできない

mysqlclientの新バージョンをリリースするために uv publish *.whl したら、次のようなエラーが発生した。

Uploading mysqlclient-2.2.7-cp310-cp310-win_amd64.whl (202.9KiB)
error: Failed to publish `mysqlclient-2.2.7-cp310-cp310-win_amd64.whl` to https://upload.pypi.org/legacy/
  Caused by: Upload failed with status code 400 Bad Request. Server says: 400 license-file introduced in metadata version 2.4, not 2.2. See https://packaging.python.org/specifications/core-metadata for more information.

setuptools のバグで、出力しているメタデータのバージョンが古いのに、より新しいバージョンのメタデータで定義されている license-file を書いてしまっているらしい。それをPyPIが厳密にチェックするようになったのでアップロードできなくなったようだ。

github.com

twineがlicense-fileを消すworkaroundを実装してくれているので、 uv publish の代わりに uvx twine upload を使えばアップロードできた。

このブログに乗せているコードは引用を除き CC0 1.0 で提供します。