Skip to content

Commit

Permalink
Accommodate for invalid metadata produced by setuptools
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Nov 27, 2024
1 parent d40245d commit ab3bf7d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Tuple, Union

from packaging import metadata
from packaging import version
from rich import print

from twine import bdist
Expand Down Expand Up @@ -143,6 +144,16 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
for key in unparsed
)
)
# setuptools emits License-File metadata fields while declaring
# Metadata-Version 2.1. This is invalid because the metadata
# specification does not allow to add arbitrary fields, and because
# the semantic implemented by setuptools is different than the one
# described in PEP 639. However, rejecting these packages would be
# too disruptive. Drop License-File metadata entries from the data
# sent to the package index if the declared metadata version is less
# than 2.4.
if version.Version(meta.get("metadata_version", "0")) < version.Version("2.4"):
meta.pop("license_files", None)
try:
metadata.Metadata.from_raw(meta)
except metadata.ExceptionGroup as group:
Expand Down

0 comments on commit ab3bf7d

Please sign in to comment.