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

pantsbuild / pants / 25441711719

06 May 2026 02:31PM UTC coverage: 92.915%. Remained the same
25441711719

push

github

web-flow
use sha pin (with comment) format for generated actions (#23312)

Per the GitHub Action best practices we recently enabled at #23249, we
should pin each action to a SHA so that the reference is actually
immutable.

This will -- I hope -- knock out a large chunk of the 421 alerts we
currently get from zizmor. The next followup would then be upgrades and
harmonizing the generated and none-generated pins.

Notice: This idea was suggested by Claude while going over pinact output
and I was surprised to see that post processing the yaml wasn't too
gross.

92206 of 99237 relevant lines covered (92.91%)

4.04 hits per line

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

100.0
/src/python/pants/backend/java/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
3✔
5

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

10
from pants.backend.java.subsystems.javac import JavacSubsystem
3✔
11
from pants.backend.java.target_types import (
3✔
12
    JavaSourcesGeneratorTarget,
13
    JavaTestsGeneratorSourcesField,
14
    JunitTestsGeneratorTarget,
15
)
16
from pants.core.goals.tailor import (
3✔
17
    AllOwnedSources,
18
    PutativeTarget,
19
    PutativeTargets,
20
    PutativeTargetsRequest,
21
)
22
from pants.engine.intrinsics import path_globs_to_paths
3✔
23
from pants.engine.rules import collect_rules, rule
3✔
24
from pants.engine.target import Target
3✔
25
from pants.engine.unions import UnionRule
3✔
26
from pants.source.filespec import FilespecMatcher
3✔
27
from pants.util.dirutil import group_by_dir
3✔
28
from pants.util.logging import LogLevel
3✔
29

30

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

35

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

44

45
@rule(level=LogLevel.DEBUG, desc="Determine candidate Java targets to create")
3✔
46
async def find_putative_targets(
3✔
47
    req: PutativeJavaTargetsRequest, all_owned_sources: AllOwnedSources, javac: JavacSubsystem
48
) -> PutativeTargets:
49
    putative_targets = []
1✔
50

51
    if javac.tailor_source_targets:
1✔
52
        all_java_files_globs = req.path_globs("*.java")
1✔
53
        all_java_files = await path_globs_to_paths(all_java_files_globs)
1✔
54
        unowned_java_files = set(all_java_files.files) - set(all_owned_sources)
1✔
55
        classified_unowned_java_files = classify_source_files(unowned_java_files)
1✔
56

57
        for tgt_type, paths in classified_unowned_java_files.items():
1✔
58
            for dirname, filenames in group_by_dir(paths).items():
1✔
59
                name = "tests" if tgt_type == JunitTestsGeneratorTarget else None
1✔
60
                putative_targets.append(
1✔
61
                    PutativeTarget.for_target_type(
62
                        tgt_type, path=dirname, name=name, triggering_sources=sorted(filenames)
63
                    )
64
                )
65

66
    return PutativeTargets(putative_targets)
1✔
67

68

69
def rules():
3✔
70
    return [
3✔
71
        *collect_rules(),
72
        UnionRule(PutativeTargetsRequest, PutativeJavaTargetsRequest),
73
    ]
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