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

pantsbuild / pants / 24144215414

08 Apr 2026 03:36PM UTC coverage: 90.427% (-2.5%) from 92.908%
24144215414

Pull #23227

github

web-flow
Merge 107cd62c9 into 9036734c9
Pull Request #23227: Fix uv PEX builder to use pex3 lock export

85 of 86 new or added lines in 2 files covered. (98.84%)

1990 existing lines in 131 files now uncovered.

83919 of 92803 relevant lines covered (90.43%)

3.58 hits per line

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

57.89
/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
2✔
5

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

10
from pants.backend.java.subsystems.javac import JavacSubsystem
2✔
11
from pants.backend.java.target_types import (
2✔
12
    JavaSourcesGeneratorTarget,
13
    JavaTestsGeneratorSourcesField,
14
    JunitTestsGeneratorTarget,
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 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 PutativeJavaTargetsRequest(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(JavaTestsGeneratorSourcesField.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 {JunitTestsGeneratorTarget: test_files, JavaSourcesGeneratorTarget: sources_files}
×
43

44

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

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

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

UNCOV
66
    return PutativeTargets(putative_targets)
×
67

68

69
def rules():
2✔
70
    return [
2✔
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