File tree 3 files changed +10
-6
lines changed
src/pip/_internal/metadata
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:
39
39
40
40
41
41
def msg_to_json (msg : Message ) -> Dict [str , Any ]:
42
+ """Convert a Message object into a JSON-compatible dictionary."""
43
+
42
44
def sanitise_header (h : Union [Header , str ]) -> str :
43
45
if isinstance (h , Header ):
44
46
chunks = []
@@ -67,6 +69,8 @@ def sanitise_header(h: Union[Header, str]) -> str:
67
69
else :
68
70
value = sanitise_header (msg .get (field ))
69
71
if key == "keywords" :
72
+ # Accept both comma-separated and space-separated
73
+ # forms, for better compatibility with old data.
70
74
if "," in value :
71
75
value = [v .strip () for v in value .split ("," )]
72
76
else :
Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ def metadata(self) -> email.message.Message:
384
384
return self ._metadata_cached ()
385
385
386
386
@property
387
- def json_metadata (self ) -> Dict [str , Any ]:
387
+ def metadata_dict (self ) -> Dict [str , Any ]:
388
388
"""PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
389
389
390
390
This should return an empty dict if the metadata file is unavailable.
Original file line number Diff line number Diff line change @@ -90,15 +90,15 @@ class FakeDistribution(BaseDistribution):
90
90
assert isinstance (direct_url .info , ArchiveInfo )
91
91
92
92
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 .
95
95
96
96
More tests are available in the original pkg_metadata project where this
97
97
function comes from, and which we may vendor in the future.
98
98
"""
99
99
wheel_path = make_wheel (name = "pkga" , version = "1.0.1" ).save_to_dir (tmp_path )
100
100
wheel = FilesystemWheel (wheel_path )
101
101
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"
You can’t perform that action at this time.
0 commit comments