Skip to content

Commit 09d36f0

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 09d36f0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

news/13112.feature.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 8 additions & 1 deletion
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
)
@@ -180,13 +182,18 @@ def print_results(
180182
if i > 0:
181183
write_output("---")
182184

185+
metadata_version_tuple = tuple(map(int, dist.metadata_version.split(".")))
186+
183187
write_output("Name: %s", dist.name)
184188
write_output("Version: %s", dist.version)
185189
write_output("Summary: %s", dist.summary)
186190
write_output("Home-page: %s", dist.homepage)
187191
write_output("Author: %s", dist.author)
188192
write_output("Author-email: %s", dist.author_email)
189-
write_output("License: %s", dist.license)
193+
if metadata_version_tuple >= (2, 4) and dist.license_expression:
194+
write_output("License-Expression: %s", dist.license_expression)
195+
else:
196+
write_output("License: %s", dist.license)
190197
write_output("Location: %s", dist.location)
191198
if dist.editable_project_location is not None:
192199
write_output(

0 commit comments

Comments
 (0)