Skip to content

Add wheel build tag to pip list columns output #13231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5210.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display wheel build tag in ``pip list`` columns output if set.
24 changes: 20 additions & 4 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from email.parser import Parser
from optparse import Values
from typing import TYPE_CHECKING, Generator, List, Optional, Sequence, Tuple, cast

Expand Down Expand Up @@ -323,17 +324,29 @@ def format_for_columns(
if running_outdated:
header.extend(["Latest", "Type"])

has_editables = any(x.editable for x in pkgs)
if has_editables:
header.append("Editable project location")
def wheel_build_tag(dist: BaseDistribution) -> Optional[str]:
try:
wheel_file = dist.read_text("WHEEL")
except FileNotFoundError:
return None
return Parser().parsestr(wheel_file).get("Build")

build_tags = [wheel_build_tag(p) for p in pkgs]
has_build_tags = any(build_tags)
if has_build_tags:
header.append("Build")

if options.verbose >= 1:
header.append("Location")
if options.verbose >= 1:
header.append("Installer")

has_editables = any(x.editable for x in pkgs)
if has_editables:
header.append("Editable project location")

data = []
for proj in pkgs:
for i, proj in enumerate(pkgs):
# if we're working on the 'outdated' list, separate out the
# latest_version and type
row = [proj.raw_name, proj.raw_version]
Expand All @@ -342,6 +355,9 @@ def format_for_columns(
row.append(str(proj.latest_version))
row.append(proj.latest_filetype)

if has_build_tags:
row.append(build_tags[i] or "")

if has_editables:
row.append(proj.editable_project_location or "")

Expand Down
14 changes: 14 additions & 0 deletions tests/functional/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TestData,
_create_test_package,
create_test_package_with_setup,
make_wheel,
wheel,
)
from tests.lib.direct_url import get_created_direct_url_path
Expand Down Expand Up @@ -751,3 +752,16 @@ def test_list_pep610_editable(script: PipTestEnvironment) -> None:
break
else:
pytest.fail("package 'testpkg' not found in pip list result")


def test_list_wheel_build(script: PipTestEnvironment) -> None:
package = make_wheel(
name="package",
version="3.0",
wheel_metadata_updates={"Build": "123"},
).save_to_dir(script.scratch_path)
script.pip("install", package, "--no-index")

result = script.pip("list")
assert "Build" in result.stdout, str(result)
assert "123" in result.stdout, str(result)
Loading