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

pantsbuild / pants / 23177125175

17 Mar 2026 03:32AM UTC coverage: 52.677% (-40.3%) from 92.932%
23177125175

Pull #23177

github

web-flow
Merge 1824dfbf4 into 0b9fdfb0e
Pull Request #23177: Bump the gha-deps group across 1 directory with 4 updates

31687 of 60153 relevant lines covered (52.68%)

1.05 hits per line

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

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

4
from __future__ import annotations
×
5

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

10
from pants.backend.kotlin.subsystems.kotlin import KotlinSubsystem
×
11
from pants.backend.kotlin.target_types import (
×
12
    KotlinJunitTestsGeneratorSourcesField,
13
    KotlinJunitTestsGeneratorTarget,
14
    KotlinSourcesGeneratorTarget,
15
)
16
from pants.core.goals.tailor import (
×
17
    AllOwnedSources,
18
    PutativeTarget,
19
    PutativeTargets,
20
    PutativeTargetsRequest,
21
)
22
from pants.engine.intrinsics import path_globs_to_paths
×
23
from pants.engine.rules import collect_rules, rule
×
24
from pants.engine.target import Target
×
25
from pants.engine.unions import UnionRule
×
26
from pants.source.filespec import FilespecMatcher
×
27
from pants.util.dirutil import group_by_dir
×
28
from pants.util.logging import LogLevel
×
29

30

31
@dataclass(frozen=True)
×
32
class PutativeKotlinTargetsRequest(PutativeTargetsRequest):
×
33
    pass
×
34

35

36
def classify_source_files(paths: Iterable[str]) -> dict[type[Target], set[str]]:
×
37
    """Returns a dict of target type -> files that belong to targets of that type."""
38
    junit_filespec_matcher = FilespecMatcher(KotlinJunitTestsGeneratorSourcesField.default, ())
×
39
    junit_files = {
×
40
        path
41
        for path in paths
42
        if os.path.basename(path)
43
        in set(junit_filespec_matcher.matches([os.path.basename(path) for path in paths]))
44
    }
45
    sources_files = set(paths) - junit_files
×
46
    return {
×
47
        KotlinJunitTestsGeneratorTarget: junit_files,
48
        KotlinSourcesGeneratorTarget: sources_files,
49
    }
50

51

52
@rule(level=LogLevel.DEBUG, desc="Determine candidate Kotlin targets to create")
×
53
async def find_putative_targets(
×
54
    req: PutativeKotlinTargetsRequest,
55
    all_owned_sources: AllOwnedSources,
56
    kotlin_subsystem: KotlinSubsystem,
57
) -> PutativeTargets:
58
    putative_targets = []
×
59

60
    if kotlin_subsystem.tailor_source_targets:
×
61
        all_kotlin_files_globs = req.path_globs("*.kt")
×
62
        all_kotlin_files = await path_globs_to_paths(all_kotlin_files_globs)
×
63
        unowned_kotlin_files = set(all_kotlin_files.files) - set(all_owned_sources)
×
64
        classified_unowned_kotlin_files = classify_source_files(unowned_kotlin_files)
×
65

66
        for tgt_type, paths in classified_unowned_kotlin_files.items():
×
67
            for dirname, filenames in group_by_dir(paths).items():
×
68
                putative_targets.append(
×
69
                    PutativeTarget.for_target_type(
70
                        tgt_type, path=dirname, name=None, triggering_sources=sorted(filenames)
71
                    )
72
                )
73

74
    return PutativeTargets(putative_targets)
×
75

76

77
def rules():
×
78
    return [
×
79
        *collect_rules(),
80
        UnionRule(PutativeTargetsRequest, PutativeKotlinTargetsRequest),
81
    ]
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