@@ -214,14 +214,7 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
214
214
215
215
# Parse and validate metadata.
216
216
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
+
225
218
# setuptools emits License-File metadata fields while declaring
226
219
# Metadata-Version 2.1. This is invalid because the metadata
227
220
# specification does not allow to add arbitrary fields, and because
@@ -232,6 +225,22 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
232
225
# than 2.4.
233
226
if version .Version (meta .get ("metadata_version" , "0" )) < version .Version ("2.4" ):
234
227
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
+
235
244
try :
236
245
metadata .Metadata .from_raw (meta )
237
246
except metadata .ExceptionGroup as group :
0 commit comments