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

pantsbuild / pants / 20328535594

18 Dec 2025 06:46AM UTC coverage: 57.969% (-22.3%) from 80.295%
20328535594

Pull #22954

github

web-flow
Merge ccc9c5409 into 407284c67
Pull Request #22954: free up disk space in runner image

39083 of 67421 relevant lines covered (57.97%)

0.91 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
1✔
5
from typing import cast
1✔
6

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

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

17

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

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

27

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

32

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