Skip to content

Commit cc804f4

Browse files
committed
Show License-Expression if present in package metadata
With Core Metadata 2.4 a new field, License-Expression, has been added. If it's present, favor it over the deprecated (with PEP 639) legacy unstructured License field. Closes: #13112
1 parent ffbf6f0 commit cc804f4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

news/13112.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prefer to display ``License-Expression`` in ``pip show`` if metadata version is at least 2.4.

src/pip/_internal/commands/show.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class _PackageInfo(NamedTuple):
6666
author: str
6767
author_email: str
6868
license: str
69+
license_expression: str
6970
entry_points: List[str]
7071
files: Optional[List[str]]
7172

@@ -161,6 +162,7 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
161162
author=metadata.get("Author", ""),
162163
author_email=metadata.get("Author-email", ""),
163164
license=metadata.get("License", ""),
165+
license_expression=metadata.get("License-Expression", ""),
164166
entry_points=entry_points,
165167
files=files,
166168
)
@@ -186,7 +188,10 @@ def print_results(
186188
write_output("Home-page: %s", dist.homepage)
187189
write_output("Author: %s", dist.author)
188190
write_output("Author-email: %s", dist.author_email)
189-
write_output("License: %s", dist.license)
191+
if dist.metadata_version >= "2.4" and dist.license_expression:
192+
write_output("License-Expression: %s", dist.license_expression)
193+
else:
194+
write_output("License: %s", dist.license)
190195
write_output("Location: %s", dist.location)
191196
if dist.editable_project_location is not None:
192197
write_output(

0 commit comments

Comments
 (0)