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

pantsbuild / pants / 25441711719

06 May 2026 02:31PM UTC coverage: 92.915%. Remained the same
25441711719

push

github

web-flow
use sha pin (with comment) format for generated actions (#23312)

Per the GitHub Action best practices we recently enabled at #23249, we
should pin each action to a SHA so that the reference is actually
immutable.

This will -- I hope -- knock out a large chunk of the 421 alerts we
currently get from zizmor. The next followup would then be upgrades and
harmonizing the generated and none-generated pins.

Notice: This idea was suggested by Claude while going over pinact output
and I was surprised to see that post processing the yaml wasn't too
gross.

92206 of 99237 relevant lines covered (92.91%)

4.04 hits per line

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

100.0
/src/python/pants/backend/codegen/thrift/apache/java/rules.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
1✔
4

5
from dataclasses import dataclass
1✔
6

7
from pants.backend.codegen.thrift.apache.java import subsystem, symbol_mapper
1✔
8
from pants.backend.codegen.thrift.apache.java.subsystem import ApacheThriftJavaSubsystem
1✔
9
from pants.backend.codegen.thrift.apache.rules import (
1✔
10
    GenerateThriftSourcesRequest,
11
    generate_apache_thrift_sources,
12
)
13
from pants.backend.codegen.thrift.target_types import (
1✔
14
    ThriftDependenciesField,
15
    ThriftSourceField,
16
    ThriftSourcesGeneratorTarget,
17
    ThriftSourceTarget,
18
)
19
from pants.backend.java.target_types import JavaSourceField
1✔
20
from pants.build_graph.address import Address
1✔
21
from pants.engine.fs import AddPrefix
1✔
22
from pants.engine.intrinsics import digest_to_snapshot
1✔
23
from pants.engine.rules import collect_rules, implicitly, rule
1✔
24
from pants.engine.target import (
1✔
25
    FieldSet,
26
    GeneratedSources,
27
    GenerateSourcesRequest,
28
    InferDependenciesRequest,
29
    InferredDependencies,
30
)
31
from pants.engine.unions import UnionRule
1✔
32
from pants.jvm.dependency_inference import artifact_mapper
1✔
33
from pants.jvm.dependency_inference.artifact_mapper import (
1✔
34
    AllJvmArtifactTargets,
35
    UnversionedCoordinate,
36
    find_jvm_artifacts_or_raise,
37
)
38
from pants.jvm.subsystems import JvmSubsystem
1✔
39
from pants.jvm.target_types import JvmResolveField, PrefixedJvmJdkField, PrefixedJvmResolveField
1✔
40
from pants.source.source_root import SourceRootRequest, get_source_root
1✔
41
from pants.util.logging import LogLevel
1✔
42

43

44
class GenerateJavaFromThriftRequest(GenerateSourcesRequest):
1✔
45
    input = ThriftSourceField
1✔
46
    output = JavaSourceField
1✔
47

48

49
@rule(desc="Generate Java from Thrift", level=LogLevel.DEBUG)
1✔
50
async def generate_java_from_thrift(
1✔
51
    request: GenerateJavaFromThriftRequest,
52
    thrift_java: ApacheThriftJavaSubsystem,
53
) -> GeneratedSources:
54
    result = await generate_apache_thrift_sources(
1✔
55
        GenerateThriftSourcesRequest(
56
            thrift_source_field=request.protocol_target[ThriftSourceField],
57
            lang_id="java",
58
            lang_options=thrift_java.gen_options,
59
            lang_name="Java",
60
        ),
61
        **implicitly(),
62
    )
63

64
    source_root = await get_source_root(SourceRootRequest.for_target(request.protocol_target))
1✔
65

66
    source_root_restored = (
1✔
67
        await digest_to_snapshot(**implicitly(AddPrefix(result.snapshot.digest, source_root.path)))
68
        if source_root.path != "."
69
        else await digest_to_snapshot(result.snapshot.digest)
70
    )
71
    return GeneratedSources(source_root_restored)
1✔
72

73

74
@dataclass(frozen=True)
1✔
75
class ApacheThriftJavaDependenciesInferenceFieldSet(FieldSet):
1✔
76
    required_fields = (ThriftDependenciesField, JvmResolveField)
1✔
77

78
    dependencies: ThriftDependenciesField
1✔
79
    resolve: JvmResolveField
1✔
80

81

82
class InferApacheThriftJavaDependencies(InferDependenciesRequest):
1✔
83
    infer_from = ApacheThriftJavaDependenciesInferenceFieldSet
1✔
84

85

86
@dataclass(frozen=True)
1✔
87
class ApacheThriftJavaRuntimeForResolveRequest:
1✔
88
    resolve_name: str
1✔
89

90

91
@dataclass(frozen=True)
1✔
92
class ApacheThriftJavaRuntimeForResolve:
1✔
93
    addresses: frozenset[Address]
1✔
94

95

96
_LIBTHRIFT_GROUP = "org.apache.thrift"
1✔
97
_LIBTHRIFT_ARTIFACT = "libthrift"
1✔
98

99

100
@rule
1✔
101
async def resolve_apache_thrift_java_runtime_for_resolve(
1✔
102
    request: ApacheThriftJavaRuntimeForResolveRequest,
103
    jvm_artifact_targets: AllJvmArtifactTargets,
104
    jvm: JvmSubsystem,
105
) -> ApacheThriftJavaRuntimeForResolve:
106
    addresses = find_jvm_artifacts_or_raise(
1✔
107
        required_coordinates=[
108
            UnversionedCoordinate(
109
                group=_LIBTHRIFT_GROUP,
110
                artifact=_LIBTHRIFT_ARTIFACT,
111
            )
112
        ],
113
        resolve=request.resolve_name,
114
        jvm_artifact_targets=jvm_artifact_targets,
115
        jvm=jvm,
116
        subsystem="the Apache Thrift runtime",
117
        target_type="protobuf_sources",
118
    )
119
    return ApacheThriftJavaRuntimeForResolve(addresses)
1✔
120

121

122
@rule
1✔
123
async def infer_apache_thrift_java_dependencies(
1✔
124
    request: InferApacheThriftJavaDependencies, jvm: JvmSubsystem
125
) -> InferredDependencies:
126
    resolve = request.field_set.resolve.normalized_value(jvm)
1✔
127

128
    dependencies_info = await resolve_apache_thrift_java_runtime_for_resolve(
1✔
129
        ApacheThriftJavaRuntimeForResolveRequest(resolve), **implicitly()
130
    )
131
    return InferredDependencies(dependencies_info.addresses)
1✔
132

133

134
def rules():
1✔
135
    return (
1✔
136
        *collect_rules(),
137
        *subsystem.rules(),
138
        *symbol_mapper.rules(),
139
        UnionRule(GenerateSourcesRequest, GenerateJavaFromThriftRequest),
140
        UnionRule(InferDependenciesRequest, InferApacheThriftJavaDependencies),
141
        ThriftSourceTarget.register_plugin_field(PrefixedJvmJdkField),
142
        ThriftSourcesGeneratorTarget.register_plugin_field(PrefixedJvmJdkField),
143
        ThriftSourceTarget.register_plugin_field(PrefixedJvmResolveField),
144
        ThriftSourcesGeneratorTarget.register_plugin_field(PrefixedJvmResolveField),
145
        # Rules needed to avoid rule graph errors.
146
        *artifact_mapper.rules(),
147
    )
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