• 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/target_types.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from pants.backend.codegen.protobuf.protoc import Protoc
×
UNCOV
5
from pants.engine.rules import collect_rules, rule
×
UNCOV
6
from pants.engine.target import (
×
7
    COMMON_TARGET_FIELDS,
8
    AllTargets,
9
    BoolField,
10
    Dependencies,
11
    MultipleSourcesField,
12
    OverridesField,
13
    SingleSourceField,
14
    Target,
15
    TargetFilesGenerator,
16
    TargetFilesGeneratorSettings,
17
    TargetFilesGeneratorSettingsRequest,
18
    Targets,
19
    generate_file_based_overrides_field_help_message,
20
    generate_multiple_sources_field_help_message,
21
)
UNCOV
22
from pants.engine.unions import UnionRule
×
UNCOV
23
from pants.util.docutil import doc_url
×
UNCOV
24
from pants.util.logging import LogLevel
×
UNCOV
25
from pants.util.strutil import help_text
×
26

27

UNCOV
28
class ProtobufDependenciesField(Dependencies):
×
UNCOV
29
    pass
×
30

31

UNCOV
32
class ProtobufGrpcToggleField(BoolField):
×
UNCOV
33
    alias = "grpc"
×
UNCOV
34
    default = False
×
UNCOV
35
    help = "Whether to generate gRPC code or not."
×
36

37

UNCOV
38
class AllProtobufTargets(Targets):
×
UNCOV
39
    pass
×
40

41

UNCOV
42
@rule(desc="Find all Protobuf targets in project", level=LogLevel.DEBUG)
×
UNCOV
43
async def find_all_protobuf_targets(targets: AllTargets) -> AllProtobufTargets:
×
44
    return AllProtobufTargets(tgt for tgt in targets if tgt.has_field(ProtobufSourceField))
×
45

46

47
# -----------------------------------------------------------------------------------------------
48
# `protobuf_source` target
49
# -----------------------------------------------------------------------------------------------
50

51

UNCOV
52
class ProtobufSourceField(SingleSourceField):
×
UNCOV
53
    expected_file_extensions = (".proto",)
×
54

55

UNCOV
56
class ProtobufSourceTarget(Target):
×
UNCOV
57
    alias = "protobuf_source"
×
UNCOV
58
    core_fields = (
×
59
        *COMMON_TARGET_FIELDS,
60
        ProtobufDependenciesField,
61
        ProtobufSourceField,
62
        ProtobufGrpcToggleField,
63
    )
UNCOV
64
    help = help_text(
×
65
        f"""
66
        A single Protobuf file used to generate various languages.
67

68
        See language-specific docs:
69
            Python: {doc_url("docs/python/integrations/protobuf-and-grpc")}
70
            Go: {doc_url("docs/go/integrations/protobuf")}
71
        """
72
    )
73

74

75
# -----------------------------------------------------------------------------------------------
76
# `protobuf_sources` target generator
77
# -----------------------------------------------------------------------------------------------
78

79

UNCOV
80
class GeneratorSettingsRequest(TargetFilesGeneratorSettingsRequest):
×
UNCOV
81
    pass
×
82

83

UNCOV
84
@rule
×
UNCOV
85
async def generator_settings(
×
86
    _: GeneratorSettingsRequest,
87
    protoc: Protoc,
88
) -> TargetFilesGeneratorSettings:
89
    return TargetFilesGeneratorSettings(
×
90
        add_dependencies_on_all_siblings=not protoc.dependency_inference
91
    )
92

93

UNCOV
94
class ProtobufSourcesGeneratingSourcesField(MultipleSourcesField):
×
UNCOV
95
    default = ("*.proto",)
×
UNCOV
96
    expected_file_extensions = (".proto",)
×
UNCOV
97
    help = generate_multiple_sources_field_help_message(
×
98
        "Example: `sources=['example.proto', 'new_*.proto', '!old_ignore*.proto']`"
99
    )
100

101

UNCOV
102
class ProtobufSourcesOverridesField(OverridesField):
×
UNCOV
103
    help = generate_file_based_overrides_field_help_message(
×
104
        ProtobufSourceTarget.alias,
105
        """
106
        overrides={
107
            "foo.proto": {"grpc": True},
108
            "bar.proto": {"description": "our user model"},
109
            ("foo.proto", "bar.proto"): {"tags": ["overridden"]},
110
        }
111
        """,
112
    )
113

114

UNCOV
115
class ProtobufSourcesGeneratorTarget(TargetFilesGenerator):
×
UNCOV
116
    alias = "protobuf_sources"
×
UNCOV
117
    core_fields = (
×
118
        *COMMON_TARGET_FIELDS,
119
        ProtobufSourcesGeneratingSourcesField,
120
        ProtobufSourcesOverridesField,
121
    )
UNCOV
122
    generated_target_cls = ProtobufSourceTarget
×
UNCOV
123
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
124
    moved_fields = (
×
125
        ProtobufGrpcToggleField,
126
        ProtobufDependenciesField,
127
    )
UNCOV
128
    settings_request_cls = GeneratorSettingsRequest
×
UNCOV
129
    help = "Generate a `protobuf_source` target for each file in the `sources` field."
×
130

131

UNCOV
132
def rules():
×
UNCOV
133
    return [
×
134
        *collect_rules(),
135
        UnionRule(TargetFilesGeneratorSettingsRequest, GeneratorSettingsRequest),
136
    ]
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