Skip to content

Commit 5aeda3b

Browse files
ichard26q0w
andauthored
Add wheel build tag to pip list columns output (#13231)
Co-authored-by: q0w <43147888+q0w@users.noreply.github.com>
1 parent ae2d221 commit 5aeda3b

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

news/5210.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display wheel build tag in ``pip list`` columns output if set.

src/pip/_internal/commands/list.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
from email.parser import Parser
34
from optparse import Values
45
from typing import TYPE_CHECKING, Generator, List, Optional, Sequence, Tuple, cast
56

@@ -323,17 +324,29 @@ def format_for_columns(
323324
if running_outdated:
324325
header.extend(["Latest", "Type"])
325326

326-
has_editables = any(x.editable for x in pkgs)
327-
if has_editables:
328-
header.append("Editable project location")
327+
def wheel_build_tag(dist: BaseDistribution) -> Optional[str]:
328+
try:
329+
wheel_file = dist.read_text("WHEEL")
330+
except FileNotFoundError:
331+
return None
332+
return Parser().parsestr(wheel_file).get("Build")
333+
334+
build_tags = [wheel_build_tag(p) for p in pkgs]
335+
has_build_tags = any(build_tags)
336+
if has_build_tags:
337+
header.append("Build")
329338

330339
if options.verbose >= 1:
331340
header.append("Location")
332341
if options.verbose >= 1:
333342
header.append("Installer")
334343

344+
has_editables = any(x.editable for x in pkgs)
345+
if has_editables:
346+
header.append("Editable project location")
347+
335348
data = []
336-
for proj in pkgs:
349+
for i, proj in enumerate(pkgs):
337350
# if we're working on the 'outdated' list, separate out the
338351
# latest_version and type
339352
row = [proj.raw_name, proj.raw_version]
@@ -342,6 +355,9 @@ def format_for_columns(
342355
row.append(str(proj.latest_version))
343356
row.append(proj.latest_filetype)
344357

358+
if has_build_tags:
359+
row.append(build_tags[i] or "")
360+
345361
if has_editables:
346362
row.append(proj.editable_project_location or "")
347363

tests/functional/test_list.py

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
TestData,
1313
_create_test_package,
1414
create_test_package_with_setup,
15+
make_wheel,
1516
wheel,
1617
)
1718
from tests.lib.direct_url import get_created_direct_url_path
@@ -751,3 +752,16 @@ def test_list_pep610_editable(script: PipTestEnvironment) -> None:
751752
break
752753
else:
753754
pytest.fail("package 'testpkg' not found in pip list result")
755+
756+
757+
def test_list_wheel_build(script: PipTestEnvironment) -> None:
758+
package = make_wheel(
759+
name="package",
760+
version="3.0",
761+
wheel_metadata_updates={"Build": "123"},
762+
).save_to_dir(script.scratch_path)
763+
script.pip("install", package, "--no-index")
764+
765+
result = script.pip("list")
766+
assert "Build" in result.stdout, str(result)
767+
assert "123" in result.stdout, str(result)

0 commit comments

Comments
 (0)