File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed
src/pip/_internal/metadata Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ def json_name(field: str) -> str:
3939
4040
4141def 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 :
Original file line number Diff line number Diff line change @@ -364,7 +364,7 @@ def metadata(self) -> email.message.Message:
364364 raise NotImplementedError ()
365365
366366 @property
367- def json_metadata (self ) -> Dict [str , Any ]:
367+ def metadata_dict (self ) -> Dict [str , Any ]:
368368 """PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
369369
370370 This should return an empty dict if the metadata file is unavailable.
Original file line number Diff line number Diff line change @@ -60,15 +60,15 @@ class FakeDistribution(BaseDistribution):
6060 assert isinstance (direct_url .info , ArchiveInfo )
6161
6262
63- def test_json_metadata (tmp_path : Path ) -> None :
64- """Basic test of BaseDistribution json_metadata .
63+ def test_metadata_dict (tmp_path : Path ) -> None :
64+ """Basic test of BaseDistribution metadata_dict .
6565
6666 More tests are available in the original pkg_metadata project where this
6767 function comes from, and which we may vendor in the future.
6868 """
6969 wheel_path = make_wheel (name = "pkga" , version = "1.0.1" ).save_to_dir (tmp_path )
7070 wheel = FilesystemWheel (wheel_path )
7171 dist = get_wheel_distribution (wheel , "pkga" )
72- json_metadata = dist .json_metadata
73- assert json_metadata ["name" ] == "pkga"
74- assert json_metadata ["version" ] == "1.0.1"
72+ metadata_dict = dist .metadata_dict
73+ assert metadata_dict ["name" ] == "pkga"
74+ assert metadata_dict ["version" ] == "1.0.1"
You can’t perform that action at this time.
0 commit comments