Skip to content

Commit 3680db0

Browse files
committed
Fix compatibility kludge to work with older packaging
Fixes #1216.
1 parent 4406034 commit 3680db0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

changelog/1217.bugfix.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix compatibility kludge for invalid License-File metadata entries emitted by
2+
build backends to work also with ``packaging`` version 24.0.

twine/package.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,7 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
214214

215215
# Parse and validate metadata.
216216
meta, unparsed = metadata.parse_email(data)
217-
if unparsed:
218-
raise exceptions.InvalidDistribution(
219-
"Invalid distribution metadata: {}".format(
220-
"; ".join(
221-
f"unrecognized or malformed field {key!r}" for key in unparsed
222-
)
223-
)
224-
)
217+
225218
# setuptools emits License-File metadata fields while declaring
226219
# Metadata-Version 2.1. This is invalid because the metadata
227220
# specification does not allow to add arbitrary fields, and because
@@ -232,6 +225,22 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
232225
# than 2.4.
233226
if version.Version(meta.get("metadata_version", "0")) < version.Version("2.4"):
234227
meta.pop("license_files", None)
228+
# Support for metadata version 2.4 requires packaging version 24.1
229+
# or later. When parsing metadata with an older packaging, the
230+
# invalid License-File fields are not understood and added to the
231+
# unparsed dictionary. Remove them to avoid triggering the
232+
# following check.
233+
unparsed.pop("license-file", None)
234+
235+
if unparsed:
236+
raise exceptions.InvalidDistribution(
237+
"Invalid distribution metadata: {}".format(
238+
"; ".join(
239+
f"unrecognized or malformed field {key!r}" for key in unparsed
240+
)
241+
)
242+
)
243+
235244
try:
236245
metadata.Metadata.from_raw(meta)
237246
except metadata.ExceptionGroup as group:

0 commit comments

Comments
 (0)