From 09d36f046d1f4f73e74125726923de189e34f3c0 Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Tue, 7 Jan 2025 12:52:35 +0100 Subject: [PATCH] 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 --- news/13112.feature.rst | 1 + src/pip/_internal/commands/show.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 news/13112.feature.rst diff --git a/news/13112.feature.rst b/news/13112.feature.rst new file mode 100644 index 00000000000..e2c85ea5629 --- /dev/null +++ b/news/13112.feature.rst @@ -0,0 +1 @@ +Prefer to display ``License-Expression`` in ``pip show`` if metadata version is at least 2.4. \ No newline at end of file diff --git a/src/pip/_internal/commands/show.py b/src/pip/_internal/commands/show.py index c54d548f5fb..b47500cf8b4 100644 --- a/src/pip/_internal/commands/show.py +++ b/src/pip/_internal/commands/show.py @@ -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]] @@ -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, ) @@ -180,13 +182,18 @@ def print_results( if i > 0: write_output("---") + metadata_version_tuple = tuple(map(int, dist.metadata_version.split("."))) + write_output("Name: %s", dist.name) write_output("Version: %s", dist.version) write_output("Summary: %s", dist.summary) 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 metadata_version_tuple >= (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(