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

pantsbuild / pants / 19250292619

11 Nov 2025 12:09AM UTC coverage: 77.865% (-2.4%) from 80.298%
19250292619

push

github

web-flow
flag non-runnable targets used with `code_quality_tool` (#22875)

2 of 5 new or added lines in 2 files covered. (40.0%)

1487 existing lines in 72 files now uncovered.

71448 of 91759 relevant lines covered (77.86%)

3.22 hits per line

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

50.0
/src/python/pants/backend/shell/goals/tailor.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
import os
2✔
7
from collections.abc import Iterable
2✔
8
from dataclasses import dataclass
2✔
9

10
from pants.backend.shell.subsystems.shell_setup import ShellSetup
2✔
11
from pants.backend.shell.target_types import (
2✔
12
    ShellSourcesGeneratorTarget,
13
    Shunit2TestsGeneratorSourcesField,
14
    Shunit2TestsGeneratorTarget,
15
)
16
from pants.core.goals.tailor import (
2✔
17
    AllOwnedSources,
18
    PutativeTarget,
19
    PutativeTargets,
20
    PutativeTargetsRequest,
21
)
22
from pants.engine.intrinsics import path_globs_to_paths
2✔
23
from pants.engine.rules import Rule, collect_rules, rule
2✔
24
from pants.engine.target import Target
2✔
25
from pants.engine.unions import UnionRule
2✔
26
from pants.source.filespec import FilespecMatcher
2✔
27
from pants.util.dirutil import group_by_dir
2✔
28
from pants.util.logging import LogLevel
2✔
29

30

31
@dataclass(frozen=True)
2✔
32
class PutativeShellTargetsRequest(PutativeTargetsRequest):
2✔
33
    pass
2✔
34

35

36
def classify_source_files(paths: Iterable[str]) -> dict[type[Target], set[str]]:
2✔
37
    """Returns a dict of target type -> files that belong to targets of that type."""
UNCOV
38
    tests_filespec_matcher = FilespecMatcher(Shunit2TestsGeneratorSourcesField.default, ())
×
UNCOV
39
    test_filenames = set(tests_filespec_matcher.matches([os.path.basename(path) for path in paths]))
×
UNCOV
40
    test_files = {path for path in paths if os.path.basename(path) in test_filenames}
×
UNCOV
41
    sources_files = set(paths) - test_files
×
UNCOV
42
    return {Shunit2TestsGeneratorTarget: test_files, ShellSourcesGeneratorTarget: sources_files}
×
43

44

45
@rule(level=LogLevel.DEBUG, desc="Determine candidate shell targets to create")
2✔
46
async def find_putative_targets(
2✔
47
    req: PutativeShellTargetsRequest, all_owned_sources: AllOwnedSources, shell_setup: ShellSetup
48
) -> PutativeTargets:
49
    if not (shell_setup.tailor_sources or shell_setup.tailor_shunit2_tests):
×
50
        return PutativeTargets()
×
51

52
    all_shell_files = await path_globs_to_paths(req.path_globs("*.sh"))
×
53
    unowned_shell_files = set(all_shell_files.files) - set(all_owned_sources)
×
54
    classified_unowned_shell_files = classify_source_files(unowned_shell_files)
×
55
    pts: list[PutativeTarget] = []
×
56
    for tgt_type, paths in classified_unowned_shell_files.items():
×
57
        for dirname, filenames in group_by_dir(paths).items():
×
58
            if tgt_type == Shunit2TestsGeneratorTarget:
×
59
                if not shell_setup.tailor_shunit2_tests:
×
60
                    continue
×
61
                name = "tests"
×
62
            else:
63
                if not shell_setup.tailor_sources:
×
64
                    continue
×
65
                name = None
×
66

67
            pts.append(
×
68
                PutativeTarget.for_target_type(
69
                    tgt_type, path=dirname, name=name, triggering_sources=sorted(filenames)
70
                )
71
            )
72
    return PutativeTargets(pts)
×
73

74

75
def rules() -> Iterable[Rule | UnionRule]:
2✔
76
    return (*collect_rules(), UnionRule(PutativeTargetsRequest, PutativeShellTargetsRequest))
2✔
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