Skip to content

Commit

Permalink
Show License-Expression if present in package metadata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
befeleme committed Jan 7, 2025
1 parent ffbf6f0 commit cc804f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/13112.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prefer to display ``License-Expression`` in ``pip show`` if metadata version is at least 2.4.
7 changes: 6 additions & 1 deletion src/pip/_internal/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class _PackageInfo(NamedTuple):
author: str
author_email: str
license: str
license_expression: str
entry_points: List[str]
files: Optional[List[str]]

Expand Down Expand Up @@ -161,6 +162,7 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
author=metadata.get("Author", ""),
author_email=metadata.get("Author-email", ""),
license=metadata.get("License", ""),
license_expression=metadata.get("License-Expression", ""),
entry_points=entry_points,
files=files,
)
Expand All @@ -186,7 +188,10 @@ def print_results(
write_output("Home-page: %s", dist.homepage)
write_output("Author: %s", dist.author)
write_output("Author-email: %s", dist.author_email)
write_output("License: %s", dist.license)
if dist.metadata_version >= "2.4" and dist.license_expression:
write_output("License-Expression: %s", dist.license_expression)
else:
write_output("License: %s", dist.license)
write_output("Location: %s", dist.location)
if dist.editable_project_location is not None:
write_output(
Expand Down

0 comments on commit cc804f4

Please sign in to comment.