Skip to content

Commit 5c7dcb9

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

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-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

+16-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,21 @@ 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 lalet. When parsing invalid metadata with an older packagign,
230+
# the invalid License-File fileds are not understood and added to
231+
# the unparsed dictionary.
232+
unparsed.pop("license-file", None)
233+
234+
if unparsed:
235+
raise exceptions.InvalidDistribution(
236+
"Invalid distribution metadata: {}".format(
237+
"; ".join(
238+
f"unrecognized or malformed field {key!r}" for key in unparsed
239+
)
240+
)
241+
)
242+
235243
try:
236244
metadata.Metadata.from_raw(meta)
237245
except metadata.ExceptionGroup as group:

0 commit comments

Comments
 (0)