From ebfed9f27e1df02f870d727e1d5c92de278fcf6a Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 23 Oct 2024 23:47:31 -0400 Subject: [PATCH] refactor: remove JSON output option Signed-off-by: Henry Schreiner --- src/packaging/metadata.py | 40 +-------------------------------------- tests/test_metadata.py | 36 ----------------------------------- 2 files changed, 1 insertion(+), 75 deletions(-) diff --git a/src/packaging/metadata.py b/src/packaging/metadata.py index 43abb5c9..1f5a715f 100644 --- a/src/packaging/metadata.py +++ b/src/packaging/metadata.py @@ -1,7 +1,6 @@ from __future__ import annotations import builtins -import dataclasses import email.feedparser import email.header import email.message @@ -273,34 +272,6 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str: _MULTI_FIELDS = {_RAW_TO_EMAIL_MAPPING[x] for x in _LIST_FIELDS | _DICT_FIELDS} -@dataclasses.dataclass -class _JSonMessageSetter: - """ - This provides an API to build a JSON message output in the same way as the - classic Message. Line breaks are preserved this way. - """ - - data: dict[str, str | list[str]] - - def __setitem__(self, name: str, value: str | None) -> None: - key = name.replace("-", "_") - if value is None: - return - - if name == "keywords": - values = (x.strip() for x in value.split(",")) - self.data[key] = [x for x in values if x] - elif name in _MULTI_FIELDS: - entry = self.data.setdefault(key, []) - assert isinstance(entry, list) - entry.append(value) - else: - self.data[key] = value - - def set_payload(self, payload: str) -> None: - self["description"] = payload - - # This class is for writing RFC822 messages class RFC822Policy(email.policy.EmailPolicy): """ @@ -882,16 +853,7 @@ def as_rfc822(self) -> RFC822Message: self._write_metadata(message) return message - def as_json(self) -> dict[str, str | list[str]]: - """ - Return a JSON message with the metadata. - """ - message: dict[str, str | list[str]] = {} - smart_message = _JSonMessageSetter(message) - self._write_metadata(smart_message) - return message - - def _write_metadata(self, message: RFC822Message | _JSonMessageSetter) -> None: + def _write_metadata(self, message: RFC822Message) -> None: """ Return an RFC822 message with the metadata. """ diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 067cbc21..7aff29d6 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -715,42 +715,6 @@ def test_large(self): } ) - assert meta.as_json() == { - "author": "Example!", - "author_email": "Unknown ", - "classifier": [ - "Development Status :: 4 - Beta", - "Programming Language :: Python", - ], - "description": "some readme 👋\n", - "description_content_type": "text/markdown", - "keywords": ["trampolim", "is", "interesting"], - "license": "some license text", - "maintainer_email": "Other Example ", - "metadata_version": "2.1", - "name": "full_metadata", - "project_url": [ - "homepage, example.com", - "documentation, readthedocs.org", - "repository, github.com/some/repo", - "changelog, github.com/some/repo/blob/master/CHANGELOG.rst", - ], - "provides_extra": ["test"], - "requires_dist": [ - "dependency1", - "dependency2>1.0.0", - "dependency3[extra]", - 'dependency4; os_name != "nt"', - 'dependency5[other-extra]>1.0; os_name == "nt"', - 'test_dependency; extra == "test"', - 'test_dependency[test_extra]; extra == "test"', - 'test_dependency[test_extra2]>3.0; os_name == "nt" and extra == "test"', - ], - "requires_python": ">=3.8", - "summary": "A package with all the metadata :)", - "version": "3.2.1", - } - core_metadata = meta.as_rfc822() assert core_metadata.items() == [ ("metadata-version", "2.1"),