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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

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

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
from dataclasses import dataclass
×
7

UNCOV
8
from pants.engine.internals.native_engine import AddressInput
×
UNCOV
9
from pants.engine.target import (
×
10
    COMMON_TARGET_FIELDS,
11
    AsyncFieldMixin,
12
    Dependencies,
13
    FieldSet,
14
    MultipleSourcesField,
15
    SingleSourceField,
16
    StringField,
17
    StringSequenceField,
18
    Target,
19
    TargetFilesGenerator,
20
    generate_multiple_sources_field_help_message,
21
)
UNCOV
22
from pants.jvm.run import jvm_run_rules
×
UNCOV
23
from pants.jvm.target_types import (
×
24
    JunitTestExtraEnvVarsField,
25
    JunitTestSourceField,
26
    JunitTestTimeoutField,
27
    JvmJdkField,
28
    JvmMainClassNameField,
29
    JvmProvidesTypesField,
30
    JvmResolveField,
31
    JvmRunnableSourceFieldSet,
32
)
UNCOV
33
from pants.util.strutil import help_text
×
34

35

UNCOV
36
class KotlinSourceField(SingleSourceField):
×
UNCOV
37
    expected_file_extensions = (".kt",)
×
38

39

UNCOV
40
class KotlinGeneratorSourcesField(MultipleSourcesField):
×
UNCOV
41
    expected_file_extensions = (".kt",)
×
42

43

UNCOV
44
class KotlincConsumedPluginIdsField(StringSequenceField):
×
UNCOV
45
    help = help_text(
×
46
        """
47
        The IDs of Kotlin compiler plugins that this source file requires.
48

49
        The plugin must be defined by a corresponding `kotlinc_plugin` AND `jvm_artifact` target,
50
        and must be present in this target's resolve's lockfile.
51

52
        If not specified, this will default to the plugins specified in
53
        `[kotlinc].plugins_for_resolve` for this target's resolve.
54
        """
55
    )
56

UNCOV
57
    alias = "kotlinc_plugins"
×
UNCOV
58
    required = False
×
59

60

UNCOV
61
@dataclass(frozen=True)
×
UNCOV
62
class KotlinFieldSet(JvmRunnableSourceFieldSet):
×
UNCOV
63
    required_fields = (KotlinSourceField,)
×
64

UNCOV
65
    sources: KotlinSourceField
×
66

67

UNCOV
68
@dataclass(frozen=True)
×
UNCOV
69
class KotlinGeneratorFieldSet(FieldSet):
×
UNCOV
70
    required_fields = (KotlinGeneratorSourcesField,)
×
71

UNCOV
72
    sources: KotlinGeneratorSourcesField
×
73

74

UNCOV
75
class KotlinDependenciesField(Dependencies):
×
UNCOV
76
    pass
×
77

78

79
# -----------------------------------------------------------------------------------------------
80
# `kotlin_source` and `kotlin_sources` targets
81
# -----------------------------------------------------------------------------------------------
82

83

UNCOV
84
class KotlinSourceTarget(Target):
×
UNCOV
85
    alias = "kotlin_source"
×
UNCOV
86
    core_fields = (
×
87
        *COMMON_TARGET_FIELDS,
88
        KotlinDependenciesField,
89
        KotlinSourceField,
90
        KotlincConsumedPluginIdsField,
91
        JvmResolveField,
92
        JvmProvidesTypesField,
93
        JvmJdkField,
94
        JvmMainClassNameField,
95
    )
UNCOV
96
    help = "A single Kotlin source file containing application or library code."
×
97

98

UNCOV
99
class KotlinSourcesGeneratorSourcesField(KotlinGeneratorSourcesField):
×
UNCOV
100
    default = ("*.kt",)
×
UNCOV
101
    help = generate_multiple_sources_field_help_message(
×
102
        "Example: `sources=['Example.kt', 'New*.kt', '!OldIgnore.kt']`"
103
    )
104

105

UNCOV
106
class KotlinSourcesGeneratorTarget(TargetFilesGenerator):
×
UNCOV
107
    alias = "kotlin_sources"
×
UNCOV
108
    core_fields = (
×
109
        *COMMON_TARGET_FIELDS,
110
        KotlinSourcesGeneratorSourcesField,
111
    )
UNCOV
112
    generated_target_cls = KotlinSourceTarget
×
UNCOV
113
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
114
    moved_fields = (
×
115
        KotlinDependenciesField,
116
        KotlincConsumedPluginIdsField,
117
        JvmResolveField,
118
        JvmJdkField,
119
        JvmProvidesTypesField,
120
        JvmMainClassNameField,
121
    )
UNCOV
122
    help = "Generate a `kotlin_source` target for each file in the `sources` field."
×
123

124

125
# -----------------------------------------------------------------------------------------------
126
# `kotlin_junit_tests`
127
# -----------------------------------------------------------------------------------------------
128

129

UNCOV
130
class KotlinJunitTestSourceField(KotlinSourceField, JunitTestSourceField):
×
UNCOV
131
    pass
×
132

133

UNCOV
134
class KotlinJunitTestDependenciesField(KotlinDependenciesField):
×
UNCOV
135
    pass
×
136

137

UNCOV
138
class KotlinJunitTestTarget(Target):
×
UNCOV
139
    alias = "kotlin_junit_test"
×
UNCOV
140
    core_fields = (
×
141
        *COMMON_TARGET_FIELDS,
142
        KotlinJunitTestDependenciesField,
143
        KotlinJunitTestSourceField,
144
        KotlincConsumedPluginIdsField,
145
        JunitTestTimeoutField,
146
        JunitTestExtraEnvVarsField,
147
        JvmResolveField,
148
        JvmJdkField,
149
        JvmProvidesTypesField,
150
    )
UNCOV
151
    help = "A single Kotlin test, run with JUnit."
×
152

153

UNCOV
154
class KotlinJunitTestsGeneratorSourcesField(KotlinGeneratorSourcesField):
×
UNCOV
155
    default = ("*Test.kt",)
×
UNCOV
156
    help = generate_multiple_sources_field_help_message(
×
157
        "Example: `sources=['*Test.kt', '!TestIgnore.kt']`"
158
    )
159

160

UNCOV
161
class KotlinJunitTestsGeneratorTarget(TargetFilesGenerator):
×
UNCOV
162
    alias = "kotlin_junit_tests"
×
UNCOV
163
    core_fields = (
×
164
        *COMMON_TARGET_FIELDS,
165
        KotlinJunitTestsGeneratorSourcesField,
166
    )
UNCOV
167
    generated_target_cls = KotlinJunitTestTarget
×
UNCOV
168
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
169
    moved_fields = (
×
170
        KotlinJunitTestDependenciesField,
171
        KotlincConsumedPluginIdsField,
172
        JunitTestTimeoutField,
173
        JunitTestExtraEnvVarsField,
174
        JvmResolveField,
175
        JvmJdkField,
176
        JvmProvidesTypesField,
177
    )
UNCOV
178
    help = "Generate a `kotlin_junit_test` target for each file in the `sources` field."
×
179

180

181
# -----------------------------------------------------------------------------------------------
182
# `kotlinc_plugin` target type
183
# -----------------------------------------------------------------------------------------------
184

185

UNCOV
186
class KotlincPluginArtifactField(StringField, AsyncFieldMixin):
×
UNCOV
187
    alias = "artifact"
×
UNCOV
188
    required = True
×
UNCOV
189
    value: str
×
UNCOV
190
    help = "The address of a `jvm_artifact` that defines a plugin for `kotlinc`."
×
191

UNCOV
192
    def to_address_input(self) -> AddressInput:
×
193
        return AddressInput.parse(
×
194
            self.value,
195
            relative_to=self.address.spec_path,
196
            description_of_origin=(
197
                f"the `{self.alias}` field in the `{KotlincPluginTarget.alias}` target {self.address}"
198
            ),
199
        )
200

201

UNCOV
202
class KotlincPluginIdField(StringField):
×
UNCOV
203
    alias = "plugin_id"
×
UNCOV
204
    help = help_text(
×
205
        """
206
        The ID for `kotlinc` to use when setting options for the plugin.
207

208
        If not set, the plugin ID defaults to the target name.
209
        """
210
    )
211

212

UNCOV
213
class KotlincPluginArgsField(StringSequenceField):
×
UNCOV
214
    alias = "plugin_args"
×
UNCOV
215
    help = help_text(
×
216
        """
217
        Optional list of argument to pass to the plugin.
218
        """
219
    )
220

221

UNCOV
222
class KotlincPluginTarget(Target):
×
UNCOV
223
    alias = "kotlinc_plugin"
×
UNCOV
224
    core_fields = (
×
225
        *COMMON_TARGET_FIELDS,
226
        KotlincPluginArtifactField,
227
        KotlincPluginIdField,
228
        KotlincPluginArgsField,
229
    )
UNCOV
230
    help = help_text(
×
231
        """
232
        A plugin for `kotlinc`.
233

234
        To enable a `kotlinc` plugin, define a target with this target type, and set the `artifact` field to the
235
        address of a `jvm_artifact` target that provides the plugin. Set the `plugin_id` field to the ID of the
236
        plugin if that name cannot be inferred from the `name` of this target.
237

238
        The standard `kotlinc` plugins are available via the following artifact coordinates and IDs:
239

240
        * All-open: `org.jetbrains.kotlin:kotlin-allopen:VERSION` (ID: `all-open`)
241
        * No-arg: `org.jetbrains.kotlin:kotlin-noarg:VERSION` (ID: `no-arg`)
242
        * SAM with receiver: `org.jetbrains.kotlin:kotlin-sam-with-receiver:VERSION` (ID: `sam-with-receiver`)
243
        * kapt (annotation processor): `org.jetbrains.kotlin:org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:VERSION` (ID: `kapt3`)
244
        * Serialization: `org.jetbrains.kotlin:kotlin-serialization:VERSION` (ID: `serialization`)
245
        """
246
    )
247

248

UNCOV
249
def rules():
×
UNCOV
250
    return [
×
251
        *jvm_run_rules(KotlinFieldSet),
252
    ]
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