Skip to content

Commit

Permalink
Rename json_metadata to metadata_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jun 23, 2022
1 parent 675b4fa commit ae67371
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/pip/_internal/metadata/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def json_name(field: str) -> str:


def msg_to_json(msg: Message) -> Dict[str, Any]:
"""Convert a Message object into a JSON-compatible dictionary."""

def sanitise_header(h: Union[Header, str]) -> str:
if isinstance(h, Header):
chunks = []
Expand Down Expand Up @@ -67,6 +69,8 @@ def sanitise_header(h: Union[Header, str]) -> str:
else:
value = sanitise_header(msg.get(field))
if key == "keywords":
# Accept both comma-separated and space-separated
# forms, for better compatibility with old data.
if "," in value:
value = [v.strip() for v in value.split(",")]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def metadata(self) -> email.message.Message:
return self._metadata_cached()

@property
def json_metadata(self) -> Dict[str, Any]:
def metadata_dict(self) -> Dict[str, Any]:
"""PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
This should return an empty dict if the metadata file is unavailable.
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/metadata/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class FakeDistribution(BaseDistribution):
assert isinstance(direct_url.info, ArchiveInfo)


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

0 comments on commit ae67371

Please sign in to comment.