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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

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

4
import itertools
×
5
from collections.abc import Iterable
×
6
from pathlib import PurePath
×
7

8
from pants.base.build_root import BuildRoot
×
9
from pants.build_graph.address import BuildFileAddressRequest
×
10
from pants.engine.addresses import Addresses
×
11
from pants.engine.console import Console
×
12
from pants.engine.goal import Goal, GoalSubsystem, LineOriented
×
13
from pants.engine.internals.build_files import find_build_file
×
14
from pants.engine.internals.graph import hydrate_sources, resolve_unexpanded_targets
×
15
from pants.engine.internals.graph import transitive_targets as transitive_targets_get
×
16
from pants.engine.rules import collect_rules, concurrently, goal_rule, implicitly
×
17
from pants.engine.target import (
×
18
    AlwaysTraverseDeps,
19
    HydrateSourcesRequest,
20
    SourcesField,
21
    Target,
22
    TransitiveTargetsRequest,
23
)
24
from pants.option.option_types import BoolOption
×
25
from pants.util.strutil import softwrap
×
26

27

28
class FiledepsSubsystem(LineOriented, GoalSubsystem):
×
29
    name = "filedeps"
×
30
    help = "List all source and BUILD files a target depends on."
×
31

32
    absolute = BoolOption(
×
33
        default=False,
34
        help=softwrap(
35
            """
36
            If True, output with absolute path. If unspecified, output with path relative to
37
            the build root.
38
            """
39
        ),
40
    )
41
    globs = BoolOption(
×
42
        default=False,
43
        help=softwrap(
44
            """
45
            Instead of outputting filenames, output the original globs used in the BUILD
46
            file. This will not include exclude globs (i.e. globs that start with `!`).
47
            """
48
        ),
49
    )
50
    transitive = BoolOption(
×
51
        default=False,
52
        help=softwrap(
53
            """
54
            If True, list files from all dependencies, including transitive dependencies. If
55
            unspecified, only list files from the target.
56
            """
57
        ),
58
    )
59

60

61
class Filedeps(Goal):
×
62
    subsystem_cls = FiledepsSubsystem
×
63
    environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY
×
64

65

66
@goal_rule
×
67
async def file_deps(
×
68
    console: Console,
69
    filedeps_subsystem: FiledepsSubsystem,
70
    build_root: BuildRoot,
71
    addresses: Addresses,
72
) -> Filedeps:
73
    targets: Iterable[Target]
74
    if filedeps_subsystem.transitive:
×
75
        transitive_targets = await transitive_targets_get(
×
76
            TransitiveTargetsRequest(
77
                addresses, should_traverse_deps_predicate=AlwaysTraverseDeps()
78
            ),
79
            **implicitly(),
80
        )
81
        targets = transitive_targets.closure
×
82
    else:
83
        # NB: We must preserve target generators, not replace with their generated targets.
84
        targets = await resolve_unexpanded_targets(addresses)
×
85

86
    build_file_addresses = await concurrently(
×
87
        find_build_file(BuildFileAddressRequest(tgt.address, description_of_origin="CLI arguments"))
88
        for tgt in targets
89
    )
90
    unique_rel_paths = {bfa.rel_path for bfa in build_file_addresses}
×
91

92
    if filedeps_subsystem.globs:
×
93
        unique_rel_paths.update(
×
94
            itertools.chain.from_iterable(
95
                tgt.get(SourcesField).filespec["includes"] for tgt in targets
96
            )
97
        )
98
    else:
99
        all_hydrated_sources = await concurrently(
×
100
            hydrate_sources(HydrateSourcesRequest(tgt.get(SourcesField)), **implicitly())
101
            for tgt in targets
102
        )
103
        unique_rel_paths.update(
×
104
            itertools.chain.from_iterable(
105
                hydrated_sources.snapshot.files for hydrated_sources in all_hydrated_sources
106
            )
107
        )
108

109
    with filedeps_subsystem.line_oriented(console) as print_stdout:
×
110
        for rel_path in sorted(unique_rel_paths):
×
111
            final_path = (
×
112
                PurePath(build_root.path, rel_path).as_posix()
113
                if filedeps_subsystem.absolute
114
                else rel_path
115
            )
116
            print_stdout(final_path)
×
117

118
    return Filedeps(exit_code=0)
×
119

120

121
def rules():
×
122
    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

© 2025 Coveralls, Inc