Skip to content

Commit e0cddaa

Browse files
committed
Simplify logic
1 parent 64f09b2 commit e0cddaa

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/pip/_internal/commands/show.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from optparse import Values
3-
from typing import Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional
3+
from typing import Generator, Iterable, Iterator, List, NamedTuple, Optional
44

55
from pip._vendor.packaging.utils import canonicalize_name
66

@@ -61,7 +61,7 @@ class _PackageInfo(NamedTuple):
6161
classifiers: List[str]
6262
summary: str
6363
homepage: str
64-
project_urls: Dict[str, str]
64+
project_urls: List[str]
6565
author: str
6666
author_email: str
6767
license: str
@@ -121,23 +121,20 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
121121

122122
metadata = dist.metadata
123123

124-
project_urls = {}
125-
for url in metadata.get_all("Project-URL", []):
126-
url_label, url = url.split(",", maxsplit=1)
127-
project_urls[url_label.strip()] = url.strip()
128-
124+
project_urls = metadata.get_all("Project-URL", [])
129125
homepage = metadata.get("Home-page", "")
130126
if not homepage:
131127
# It's common that there is a "homepage" Project-URL, but Home-page
132128
# remains unset (especially as PEP 621 doesn't surface the field).
133129
#
134130
# This logic was taken from PyPI's codebase.
135-
for url_label, url in project_urls.items():
131+
for url in project_urls:
132+
url_label, url = url.split(",", maxsplit=1)
136133
normalized_label = (
137-
url_label.casefold().replace("-", "").replace("_", "")
134+
url_label.casefold().replace("-", "").replace("_", "").strip()
138135
)
139136
if normalized_label == "homepage":
140-
homepage = url
137+
homepage = url.strip()
141138
break
142139

143140
yield _PackageInfo(
@@ -200,8 +197,8 @@ def print_results(
200197
for entry in dist.entry_points:
201198
write_output(" %s", entry.strip())
202199
write_output("Project-URLs:")
203-
for label, url in dist.project_urls.items():
204-
write_output(f" {label}, {url}")
200+
for project_url in dist.project_urls:
201+
write_output(" %s", project_url)
205202
if list_files:
206203
write_output("Files:")
207204
if dist.files is None:

0 commit comments

Comments
 (0)