• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 22523112068

28 Feb 2026 03:01PM UTC coverage: 90.325% (-2.6%) from 92.93%
22523112068

push

github

web-flow
Prepare 2.32.0.dev3 (#23148)

82731 of 91593 relevant lines covered (90.32%)

3.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.33
/src/python/pants/backend/project_info/list_targets.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
import logging
4✔
5
from typing import cast
4✔
6

7
from pants.engine.addresses import Address, Addresses
4✔
8
from pants.engine.console import Console
4✔
9
from pants.engine.goal import Goal, GoalSubsystem, LineOriented
4✔
10
from pants.engine.internals.graph import resolve_unexpanded_targets
4✔
11
from pants.engine.rules import collect_rules, goal_rule
4✔
12
from pants.engine.target import DescriptionField
4✔
13
from pants.option.option_types import BoolOption
4✔
14

15
logger = logging.getLogger(__name__)
4✔
16

17

18
class ListSubsystem(LineOriented, GoalSubsystem):
4✔
19
    name = "list"
4✔
20
    help = "Lists all targets matching the file or target arguments."
4✔
21

22
    documented = BoolOption(
4✔
23
        default=False,
24
        help="Print only targets that are documented with a description.",
25
    )
26

27

28
class List(Goal):
4✔
29
    subsystem_cls = ListSubsystem
4✔
30
    environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY
4✔
31

32

33
@goal_rule
4✔
34
async def list_targets(
4✔
35
    addresses: Addresses, list_subsystem: ListSubsystem, console: Console
36
) -> List:
37
    if not addresses:
×
38
        logger.warning(f"No targets were matched in goal `{list_subsystem.name}`.")
×
39
        return List(exit_code=0)
×
40

41
    if list_subsystem.documented:
×
42
        # We must preserve target generators, not replace with their generated targets.
43
        targets = await resolve_unexpanded_targets(addresses)
×
44
        addresses_with_descriptions = cast(
×
45
            dict[Address, str],
46
            {
47
                tgt.address: tgt[DescriptionField].value
48
                for tgt in targets
49
                if tgt.get(DescriptionField).value is not None
50
            },
51
        )
52
        with list_subsystem.line_oriented(console) as print_stdout:
×
53
            for address, description in addresses_with_descriptions.items():
×
54
                formatted_description = "\n  ".join(description.strip().split("\n"))
×
55
                print_stdout(f"{address.spec}\n  {formatted_description}")
×
56
        return List(exit_code=0)
×
57

58
    with list_subsystem.line_oriented(console) as print_stdout:
×
59
        for address in sorted(addresses):
×
60
            print_stdout(address.spec)
×
61
    return List(exit_code=0)
×
62

63

64
def rules():
4✔
65
    return collect_rules()
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc