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

pantsbuild / pants / 18517631058

15 Oct 2025 04:18AM UTC coverage: 69.207% (-11.1%) from 80.267%
18517631058

Pull #22745

github

web-flow
Merge 642a76ca1 into 99919310e
Pull Request #22745: [windows] Add windows support in the stdio crate.

53815 of 77759 relevant lines covered (69.21%)

2.42 hits per line

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

0.0
/src/python/pants/backend/kotlin/dependency_inference/rules.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
×
4

5
from dataclasses import dataclass
×
6

7
from pants.backend.kotlin.dependency_inference import kotlin_parser, symbol_mapper
×
8
from pants.backend.kotlin.dependency_inference.kotlin_parser import (
×
9
    resolve_fallible_result_to_analysis,
10
)
11
from pants.backend.kotlin.subsystems.kotlin import KotlinSubsystem
×
12
from pants.backend.kotlin.subsystems.kotlin_infer import KotlinInferSubsystem
×
13
from pants.backend.kotlin.target_types import KotlinDependenciesField, KotlinSourceField
×
14
from pants.build_graph.address import Address
×
15
from pants.core.util_rules.source_files import SourceFilesRequest
×
16
from pants.engine.internals.graph import determine_explicitly_provided_dependencies
×
17
from pants.engine.internals.selectors import concurrently
×
18
from pants.engine.rules import collect_rules, implicitly, rule
×
19
from pants.engine.target import (
×
20
    DependenciesRequest,
21
    FieldSet,
22
    InferDependenciesRequest,
23
    InferredDependencies,
24
)
25
from pants.engine.unions import UnionRule
×
26
from pants.jvm.dependency_inference import artifact_mapper
×
27
from pants.jvm.dependency_inference import symbol_mapper as jvm_symbol_mapper
×
28
from pants.jvm.dependency_inference.artifact_mapper import (
×
29
    AllJvmArtifactTargets,
30
    find_jvm_artifacts_or_raise,
31
)
32
from pants.jvm.dependency_inference.symbol_mapper import SymbolMapping
×
33
from pants.jvm.resolve.coordinate import Coordinate
×
34
from pants.jvm.subsystems import JvmSubsystem
×
35
from pants.jvm.target_types import JvmResolveField
×
36
from pants.util.ordered_set import OrderedSet
×
37

38

39
@dataclass(frozen=True)
×
40
class KotlinSourceDependenciesInferenceFieldSet(FieldSet):
×
41
    required_fields = (KotlinSourceField, KotlinDependenciesField, JvmResolveField)
×
42

43
    source: KotlinSourceField
×
44
    dependencies: KotlinDependenciesField
×
45
    resolve: JvmResolveField
×
46

47

48
class InferKotlinSourceDependencies(InferDependenciesRequest):
×
49
    infer_from = KotlinSourceDependenciesInferenceFieldSet
×
50

51

52
@rule(desc="Inferring Kotlin dependencies by analyzing sources")
×
53
async def infer_kotlin_dependencies_via_source_analysis(
×
54
    request: InferKotlinSourceDependencies,
55
    kotlin_infer_subsystem: KotlinInferSubsystem,
56
    jvm: JvmSubsystem,
57
    symbol_mapping: SymbolMapping,
58
) -> InferredDependencies:
59
    if not kotlin_infer_subsystem.imports:
×
60
        return InferredDependencies([])
×
61

62
    address = request.field_set.address
×
63
    explicitly_provided_deps, analysis = await concurrently(
×
64
        determine_explicitly_provided_dependencies(
65
            **implicitly(DependenciesRequest(request.field_set.dependencies))
66
        ),
67
        resolve_fallible_result_to_analysis(
68
            **implicitly(SourceFilesRequest([request.field_set.source]))
69
        ),
70
    )
71

72
    symbols: OrderedSet[str] = OrderedSet()
×
73
    if kotlin_infer_subsystem.imports:
×
74
        symbols.update(imp.name for imp in analysis.imports)
×
75
    if kotlin_infer_subsystem.consumed_types:
×
76
        symbols.update(analysis.fully_qualified_consumed_symbols())
×
77

78
    resolve = request.field_set.resolve.normalized_value(jvm)
×
79

80
    dependencies: OrderedSet[Address] = OrderedSet()
×
81
    for symbol in symbols:
×
82
        for matches in symbol_mapping.addresses_for_symbol(symbol, resolve).values():
×
83
            explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
×
84
                matches,
85
                address,
86
                import_reference="type",
87
                context=f"The target {address} imports `{symbol}`",
88
            )
89

90
            maybe_disambiguated = explicitly_provided_deps.disambiguated(matches)
×
91
            if maybe_disambiguated:
×
92
                dependencies.add(maybe_disambiguated)
×
93

94
    return InferredDependencies(dependencies)
×
95

96

97
@dataclass(frozen=True)
×
98
class KotlinRuntimeDependencyInferenceFieldSet(FieldSet):
×
99
    required_fields = (KotlinDependenciesField, JvmResolveField)
×
100

101
    dependencies: KotlinDependenciesField
×
102
    resolve: JvmResolveField
×
103

104

105
class InferKotlinRuntimeDependencyRequest(InferDependenciesRequest):
×
106
    infer_from = KotlinRuntimeDependencyInferenceFieldSet
×
107

108

109
@dataclass(frozen=True)
×
110
class KotlinRuntimeForResolveRequest:
×
111
    resolve_name: str
×
112

113

114
@dataclass(frozen=True)
×
115
class KotlinRuntimeForResolve:
×
116
    addresses: frozenset[Address]
×
117

118

119
@rule
×
120
async def resolve_kotlin_runtime_for_resolve(
×
121
    request: KotlinRuntimeForResolveRequest,
122
    jvm_artifact_targets: AllJvmArtifactTargets,
123
    jvm: JvmSubsystem,
124
    kotlin_subsystem: KotlinSubsystem,
125
) -> KotlinRuntimeForResolve:
126
    kotlin_version = kotlin_subsystem.version_for_resolve(request.resolve_name)
×
127
    addresses = find_jvm_artifacts_or_raise(
×
128
        required_coordinates=[
129
            Coordinate(
130
                group="org.jetbrains.kotlin",
131
                artifact="kotlin-stdlib",
132
                version=kotlin_version,
133
            ),
134
            Coordinate(
135
                group="org.jetbrains.kotlin",
136
                artifact="kotlin-reflect",
137
                version=kotlin_version,
138
            ),
139
            Coordinate(
140
                group="org.jetbrains.kotlin",
141
                artifact="kotlin-script-runtime",
142
                version=kotlin_version,
143
            ),
144
        ],
145
        resolve=request.resolve_name,
146
        jvm_artifact_targets=jvm_artifact_targets,
147
        jvm=jvm,
148
        subsystem="the Kotlin runtime",
149
        target_type="kotlin_sources",
150
        requirement_source="the relevant entry for this resolve in the `[kotlin].version_for_resolve` option",
151
    )
152
    return KotlinRuntimeForResolve(addresses)
×
153

154

155
@rule(desc="Infer dependency on Kotlin runtime artifacts for Kotlin targets.")
×
156
async def infer_kotlin_stdlib_dependency(
×
157
    request: InferKotlinRuntimeDependencyRequest,
158
    jvm: JvmSubsystem,
159
) -> InferredDependencies:
160
    resolve = request.field_set.resolve.normalized_value(jvm)
×
161

162
    kotlin_runtime_target_info = await resolve_kotlin_runtime_for_resolve(
×
163
        KotlinRuntimeForResolveRequest(resolve), **implicitly()
164
    )
165
    return InferredDependencies(kotlin_runtime_target_info.addresses)
×
166

167

168
def rules():
×
169
    return (
×
170
        *collect_rules(),
171
        *kotlin_parser.rules(),
172
        *symbol_mapper.rules(),
173
        *jvm_symbol_mapper.rules(),
174
        *artifact_mapper.rules(),
175
        UnionRule(InferDependenciesRequest, InferKotlinSourceDependencies),
176
        UnionRule(InferDependenciesRequest, InferKotlinRuntimeDependencyRequest),
177
    )
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