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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 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).
3
from __future__ import annotations
×
4

5
from dataclasses import dataclass
×
6

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

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

27

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

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

40

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

44

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

49

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

54

55
@rule
×
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

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

81

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

86

87
@rule
×
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

125
@rule
×
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

146
def rules():
×
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