33
33
)
34
34
35
35
import importlib_metadata
36
+ import packaging .version
36
37
import pkginfo
37
38
from rich import print
38
39
@@ -134,14 +135,15 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
134
135
f .capitalize () for f in ["name" , "version" ] if not getattr (meta , f )
135
136
]
136
137
if missing_fields :
137
- raise exceptions .InvalidDistribution (
138
- "Metadata is missing required fields: "
139
- f"{ ', ' .join (missing_fields )} ."
140
- # TODO: Remove this section after requiring pkginfo>=1.11
141
- "\n Make sure the distribution includes the files where those fields "
142
- "are specified, and is using a supported Metadata-Version: "
143
- f"{ ', ' .join (supported_metadata )} ."
144
- )
138
+ msg = f"Metadata is missing required fields: { ', ' .join (missing_fields )} ."
139
+ if cls ._pkginfo_before_1_11 ():
140
+ msg += (
141
+ "\n "
142
+ "Make sure the distribution includes the files where those fields "
143
+ "are specified, and is using a supported Metadata-Version: "
144
+ f"{ ', ' .join (supported_metadata )} ."
145
+ )
146
+ raise exceptions .InvalidDistribution (msg )
145
147
146
148
py_version : Optional [str ]
147
149
if dtype == "bdist_egg" :
@@ -163,6 +165,11 @@ def _is_unknown_metadata_version(
163
165
NMV = getattr (pkginfo .distribution , "NewMetadataVersion" , None )
164
166
return any (warning .category is NMV for warning in captured )
165
167
168
+ @staticmethod
169
+ def _pkginfo_before_1_11 () -> bool :
170
+ ver = packaging .version .Version (importlib_metadata .version ("pkginfo" ))
171
+ return ver < packaging .version .Version ("1.11" )
172
+
166
173
def metadata_dictionary (self ) -> Dict [str , MetadataValue ]:
167
174
"""Merge multiple sources of metadata into a single dictionary.
168
175
0 commit comments