Skip to content

Commit ae67371

Browse files
committed
Rename json_metadata to metadata_dict
1 parent 675b4fa commit ae67371

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/pip/_internal/metadata/_json.py

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def json_name(field: str) -> str:
3939

4040

4141
def msg_to_json(msg: Message) -> Dict[str, Any]:
42+
"""Convert a Message object into a JSON-compatible dictionary."""
43+
4244
def sanitise_header(h: Union[Header, str]) -> str:
4345
if isinstance(h, Header):
4446
chunks = []
@@ -67,6 +69,8 @@ def sanitise_header(h: Union[Header, str]) -> str:
6769
else:
6870
value = sanitise_header(msg.get(field))
6971
if key == "keywords":
72+
# Accept both comma-separated and space-separated
73+
# forms, for better compatibility with old data.
7074
if "," in value:
7175
value = [v.strip() for v in value.split(",")]
7276
else:

src/pip/_internal/metadata/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def metadata(self) -> email.message.Message:
384384
return self._metadata_cached()
385385

386386
@property
387-
def json_metadata(self) -> Dict[str, Any]:
387+
def metadata_dict(self) -> Dict[str, Any]:
388388
"""PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
389389
390390
This should return an empty dict if the metadata file is unavailable.

tests/unit/metadata/test_metadata.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ class FakeDistribution(BaseDistribution):
9090
assert isinstance(direct_url.info, ArchiveInfo)
9191

9292

93-
def test_json_metadata(tmp_path: Path) -> None:
94-
"""Basic test of BaseDistribution json_metadata.
93+
def test_metadata_dict(tmp_path: Path) -> None:
94+
"""Basic test of BaseDistribution metadata_dict.
9595
9696
More tests are available in the original pkg_metadata project where this
9797
function comes from, and which we may vendor in the future.
9898
"""
9999
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmp_path)
100100
wheel = FilesystemWheel(wheel_path)
101101
dist = get_wheel_distribution(wheel, "pkga")
102-
json_metadata = dist.json_metadata
103-
assert json_metadata["name"] == "pkga"
104-
assert json_metadata["version"] == "1.0.1"
102+
metadata_dict = dist.metadata_dict
103+
assert metadata_dict["name"] == "pkga"
104+
assert metadata_dict["version"] == "1.0.1"

0 commit comments

Comments
 (0)