• 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/codegen/protobuf/java/dependency_inference.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from __future__ import annotations
×
4

UNCOV
5
from dataclasses import dataclass
×
6

UNCOV
7
from pants.backend.codegen.protobuf.target_types import (
×
8
    ProtobufDependenciesField,
9
    ProtobufGrpcToggleField,
10
)
UNCOV
11
from pants.build_graph.address import Address
×
UNCOV
12
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
13
from pants.engine.target import FieldSet, InferDependenciesRequest, InferredDependencies
×
UNCOV
14
from pants.engine.unions import UnionRule
×
UNCOV
15
from pants.jvm.dependency_inference.artifact_mapper import (
×
16
    AllJvmArtifactTargets,
17
    UnversionedCoordinate,
18
    find_jvm_artifacts_or_raise,
19
)
UNCOV
20
from pants.jvm.dependency_inference.artifact_mapper import rules as artifact_mapper_rules
×
UNCOV
21
from pants.jvm.subsystems import JvmSubsystem
×
UNCOV
22
from pants.jvm.target_types import JvmResolveField
×
23

UNCOV
24
_PROTOBUF_JAVA_RUNTIME_GROUP = "com.google.protobuf"
×
UNCOV
25
_PROTOBUF_JAVA_RUNTIME_ARTIFACT = "protobuf-java"
×
26

27

UNCOV
28
@dataclass(frozen=True)
×
UNCOV
29
class ProtobufJavaRuntimeDependencyInferenceFieldSet(FieldSet):
×
UNCOV
30
    required_fields = (
×
31
        ProtobufDependenciesField,
32
        JvmResolveField,
33
        ProtobufGrpcToggleField,
34
    )
35

UNCOV
36
    dependencies: ProtobufDependenciesField
×
UNCOV
37
    resolve: JvmResolveField
×
UNCOV
38
    grpc: ProtobufGrpcToggleField
×
39

40

UNCOV
41
class InferProtobufJavaRuntimeDependencyRequest(InferDependenciesRequest):
×
UNCOV
42
    infer_from = ProtobufJavaRuntimeDependencyInferenceFieldSet
×
43

44

UNCOV
45
@dataclass(frozen=True)
×
UNCOV
46
class ProtobufJavaRuntimeForResolveRequest:
×
UNCOV
47
    resolve_name: str
×
48

49

UNCOV
50
@dataclass(frozen=True)
×
UNCOV
51
class ProtobufJavaRuntimeForResolve:
×
UNCOV
52
    addresses: frozenset[Address]
×
53

54

UNCOV
55
@rule
×
UNCOV
56
async def resolve_protobuf_java_runtime_for_resolve(
×
57
    request: ProtobufJavaRuntimeForResolveRequest,
58
    jvm_artifact_targets: AllJvmArtifactTargets,
59
    jvm: JvmSubsystem,
60
) -> ProtobufJavaRuntimeForResolve:
61
    addresses = find_jvm_artifacts_or_raise(
×
62
        required_coordinates=[
63
            UnversionedCoordinate(
64
                group=_PROTOBUF_JAVA_RUNTIME_GROUP,
65
                artifact=_PROTOBUF_JAVA_RUNTIME_ARTIFACT,
66
            )
67
        ],
68
        resolve=request.resolve_name,
69
        jvm_artifact_targets=jvm_artifact_targets,
70
        jvm=jvm,
71
        subsystem="the Protobuf Java runtime",
72
        target_type="protobuf_sources",
73
    )
74
    return ProtobufJavaRuntimeForResolve(addresses)
×
75

76

UNCOV
77
@dataclass(frozen=True)
×
UNCOV
78
class ProtobufJavaGrpcRuntimeForResolveRequest:
×
UNCOV
79
    resolve_name: str
×
80

81

UNCOV
82
@dataclass(frozen=True)
×
UNCOV
83
class ProtobufJavaGrpcRuntimeForResolve:
×
UNCOV
84
    addresses: frozenset[Address]
×
85

86

UNCOV
87
@rule
×
UNCOV
88
async def resolve_protobuf_java_grpc_runtime_for_resolve(
×
89
    request: ProtobufJavaGrpcRuntimeForResolveRequest,
90
    jvm_artifact_targets: AllJvmArtifactTargets,
91
    jvm: JvmSubsystem,
92
) -> ProtobufJavaGrpcRuntimeForResolve:
93
    addresses = find_jvm_artifacts_or_raise(
×
94
        required_coordinates=[
95
            # For non-Android uses:
96
            # TODO: Maybe support Android jars? See https://github.com/grpc/grpc-java#download for
97
            # the differences in required jars.
98
            UnversionedCoordinate(
99
                group="io.grpc",
100
                artifact="grpc-netty-shaded",
101
            ),
102
            UnversionedCoordinate(
103
                group="io.grpc",
104
                artifact="grpc-protobuf",
105
            ),
106
            UnversionedCoordinate(
107
                group="io.grpc",
108
                artifact="grpc-stub",
109
            ),
110
            # TODO: This is only required for JDK 9+ according to https://github.com/grpc/grpc-java#download.
111
            UnversionedCoordinate(
112
                group="org.apache.tomcat",
113
                artifact="annotations-api",
114
            ),
115
        ],
116
        resolve=request.resolve_name,
117
        jvm_artifact_targets=jvm_artifact_targets,
118
        jvm=jvm,
119
        subsystem="the Protobuf Java gRPC runtime",
120
        target_type="protobuf_sources",
121
    )
122
    return ProtobufJavaGrpcRuntimeForResolve(addresses)
×
123

124

UNCOV
125
@rule
×
UNCOV
126
async def infer_protobuf_java_runtime_dependency(
×
127
    request: InferProtobufJavaRuntimeDependencyRequest,
128
    jvm: JvmSubsystem,
129
) -> InferredDependencies:
130
    resolve = request.field_set.resolve.normalized_value(jvm)
×
131

132
    protobuf_java_runtime_target_info = await resolve_protobuf_java_runtime_for_resolve(
×
133
        ProtobufJavaRuntimeForResolveRequest(resolve), **implicitly()
134
    )
135
    addresses: set[Address] = set(protobuf_java_runtime_target_info.addresses)
×
136

137
    if request.field_set.grpc.value:
×
138
        grpc_runtime_info = await resolve_protobuf_java_grpc_runtime_for_resolve(
×
139
            ProtobufJavaGrpcRuntimeForResolveRequest(resolve), **implicitly()
140
        )
141
        addresses.update(grpc_runtime_info.addresses)
×
142

143
    return InferredDependencies(frozenset(addresses))
×
144

145

UNCOV
146
def rules():
×
UNCOV
147
    return (
×
148
        *collect_rules(),
149
        *artifact_mapper_rules(),
150
        UnionRule(InferDependenciesRequest, InferProtobufJavaRuntimeDependencyRequest),
151
    )
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

© 2025 Coveralls, Inc