Skip to content

Commit

Permalink
Only emit the supported metadata versions notice for older pkginfo ve…
Browse files Browse the repository at this point in the history
…rsions.
  • Loading branch information
jaraco committed Jun 25, 2024
1 parent e780b0f commit 71346e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies = [
"keyring >= 15.1",
"rfc3986 >= 1.4.0",
"rich >= 12.0.0",
"packaging",

# workaround for #1116
"pkginfo < 1.11",
Expand Down
23 changes: 15 additions & 8 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)

import importlib_metadata
import packaging.version
import pkginfo
from rich import print

Expand Down Expand Up @@ -134,14 +135,15 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
f.capitalize() for f in ["name", "version"] if not getattr(meta, f)
]
if missing_fields:
raise exceptions.InvalidDistribution(
"Metadata is missing required fields: "
f"{', '.join(missing_fields)}."
# TODO: Remove this section after requiring pkginfo>=1.11
"\nMake sure the distribution includes the files where those fields "
"are specified, and is using a supported Metadata-Version: "
f"{', '.join(supported_metadata)}."
)
msg = f"Metadata is missing required fields: {', '.join(missing_fields)}."
if cls._pkginfo_before_1_11():
msg += (
"\n"
"Make sure the distribution includes the files where those fields "
"are specified, and is using a supported Metadata-Version: "
f"{', '.join(supported_metadata)}."
)
raise exceptions.InvalidDistribution(msg)

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

@staticmethod
def _pkginfo_before_1_11() -> bool:
ver = packaging.version.Version(importlib_metadata.version("pkginfo"))
return ver < packaging.version.Version("1.11")

def metadata_dictionary(self) -> Dict[str, MetadataValue]:
"""Merge multiple sources of metadata into a single dictionary.
Expand Down

0 comments on commit 71346e0

Please sign in to comment.