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

pantsbuild / pants / 20632486505

01 Jan 2026 04:21AM UTC coverage: 43.231% (-37.1%) from 80.281%
20632486505

Pull #22962

github

web-flow
Merge 08d5c63b0 into f52ab6675
Pull Request #22962: Bump the gha-deps group across 1 directory with 6 updates

26122 of 60424 relevant lines covered (43.23%)

0.86 hits per line

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

0.0
/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
×
5
from typing import cast
×
6

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

15
logger = logging.getLogger(__name__)
×
16

17

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

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

27

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

32

33
@goal_rule
×
34
async def list_targets(
×
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():
×
65
    return collect_rules()
×
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