Skip to content

Commit 71346e0

Browse files
committed
Only emit the supported metadata versions notice for older pkginfo versions.
1 parent e780b0f commit 71346e0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
"keyring >= 15.1",
4040
"rfc3986 >= 1.4.0",
4141
"rich >= 12.0.0",
42+
"packaging",
4243

4344
# workaround for #1116
4445
"pkginfo < 1.11",

twine/package.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434

3535
import importlib_metadata
36+
import packaging.version
3637
import pkginfo
3738
from rich import print
3839

@@ -134,14 +135,15 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
134135
f.capitalize() for f in ["name", "version"] if not getattr(meta, f)
135136
]
136137
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-
"\nMake 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)
145147

146148
py_version: Optional[str]
147149
if dtype == "bdist_egg":
@@ -163,6 +165,11 @@ def _is_unknown_metadata_version(
163165
NMV = getattr(pkginfo.distribution, "NewMetadataVersion", None)
164166
return any(warning.category is NMV for warning in captured)
165167

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+
166173
def metadata_dictionary(self) -> Dict[str, MetadataValue]:
167174
"""Merge multiple sources of metadata into a single dictionary.
168175

0 commit comments

Comments
 (0)