• 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/lint/buf/lint_rules.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from dataclasses import dataclass
×
UNCOV
4
from typing import Any
×
5

UNCOV
6
from pants.backend.codegen.protobuf.lint.buf.skip_field import SkipBufLintField
×
UNCOV
7
from pants.backend.codegen.protobuf.lint.buf.subsystem import BufSubsystem
×
UNCOV
8
from pants.backend.codegen.protobuf.target_types import (
×
9
    ProtobufDependenciesField,
10
    ProtobufSourceField,
11
)
UNCOV
12
from pants.core.goals.lint import LintResult, LintTargetsRequest, Partitions
×
UNCOV
13
from pants.core.util_rules.config_files import find_config_file
×
UNCOV
14
from pants.core.util_rules.external_tool import download_external_tool
×
UNCOV
15
from pants.core.util_rules.source_files import SourceFilesRequest
×
UNCOV
16
from pants.core.util_rules.stripped_source_files import strip_source_roots
×
UNCOV
17
from pants.engine.fs import MergeDigests
×
UNCOV
18
from pants.engine.internals.graph import transitive_targets as transitive_targets_get
×
UNCOV
19
from pants.engine.intrinsics import execute_process, merge_digests
×
UNCOV
20
from pants.engine.platform import Platform
×
UNCOV
21
from pants.engine.process import Process
×
UNCOV
22
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
×
UNCOV
23
from pants.engine.target import FieldSet, Target, TransitiveTargetsRequest
×
UNCOV
24
from pants.util.logging import LogLevel
×
UNCOV
25
from pants.util.meta import classproperty
×
UNCOV
26
from pants.util.strutil import pluralize
×
27

28

UNCOV
29
@dataclass(frozen=True)
×
UNCOV
30
class BufFieldSet(FieldSet):
×
UNCOV
31
    required_fields = (ProtobufSourceField,)
×
32

33
    sources: ProtobufSourceField
34
    dependencies: ProtobufDependenciesField
35

UNCOV
36
    @classmethod
×
UNCOV
37
    def opt_out(cls, tgt: Target) -> bool:
×
38
        return tgt.get(SkipBufLintField).value
×
39

40

UNCOV
41
class BufLintRequest(LintTargetsRequest):
×
UNCOV
42
    field_set_type = BufFieldSet
×
UNCOV
43
    tool_subsystem = BufSubsystem  # type: ignore[assignment]
×
44

UNCOV
45
    @classproperty
×
UNCOV
46
    def tool_name(cls) -> str:
×
47
        return "buf lint"
×
48

UNCOV
49
    @classproperty
×
UNCOV
50
    def tool_id(cls) -> str:
×
51
        return "buf-lint"
×
52

53

UNCOV
54
@rule
×
UNCOV
55
async def partition_buf(
×
56
    request: BufLintRequest.PartitionRequest[BufFieldSet], buf: BufSubsystem
57
) -> Partitions[BufFieldSet, Any]:
58
    return Partitions() if buf.lint_skip else Partitions.single_partition(request.field_sets)
×
59

60

UNCOV
61
@rule(desc="Lint with buf lint", level=LogLevel.DEBUG)
×
UNCOV
62
async def run_buf(
×
63
    request: BufLintRequest.Batch[BufFieldSet, Any], buf: BufSubsystem, platform: Platform
64
) -> LintResult:
65
    transitive_targets = await transitive_targets_get(
×
66
        TransitiveTargetsRequest(field_set.address for field_set in request.elements),
67
        **implicitly(),
68
    )
69

70
    all_stripped_sources_request = strip_source_roots(
×
71
        **implicitly(
72
            SourceFilesRequest(
73
                tgt[ProtobufSourceField]
74
                for tgt in transitive_targets.closure
75
                if tgt.has_field(ProtobufSourceField)
76
            )
77
        )
78
    )
79
    target_stripped_sources_request = strip_source_roots(
×
80
        **implicitly(
81
            SourceFilesRequest(
82
                (field_set.sources for field_set in request.elements),
83
                for_sources_types=(ProtobufSourceField,),
84
                enable_codegen=True,
85
            )
86
        )
87
    )
88

89
    download_buf_get = download_external_tool(buf.get_request(platform))
×
90

91
    config_files_get = find_config_file(buf.config_request)
×
92

93
    (
×
94
        target_sources_stripped,
95
        all_sources_stripped,
96
        downloaded_buf,
97
        config_files,
98
    ) = await concurrently(
99
        target_stripped_sources_request,
100
        all_stripped_sources_request,
101
        download_buf_get,
102
        config_files_get,
103
    )
104

105
    input_digest = await merge_digests(
×
106
        MergeDigests(
107
            (
108
                target_sources_stripped.snapshot.digest,
109
                all_sources_stripped.snapshot.digest,
110
                downloaded_buf.digest,
111
                config_files.snapshot.digest,
112
            )
113
        )
114
    )
115

116
    config_arg = ["--config", buf.config] if buf.config else []
×
117

118
    process_result = await execute_process(
×
119
        Process(
120
            argv=[
121
                downloaded_buf.exe,
122
                "lint",
123
                *config_arg,
124
                *buf.lint_args,
125
                "--path",
126
                ",".join(target_sources_stripped.snapshot.files),
127
            ],
128
            input_digest=input_digest,
129
            description=f"Run buf lint on {pluralize(len(request.elements), 'file')}.",
130
            level=LogLevel.DEBUG,
131
        ),
132
        **implicitly(),
133
    )
134
    return LintResult.create(request, process_result)
×
135

136

UNCOV
137
def rules():
×
UNCOV
138
    return [
×
139
        *collect_rules(),
140
        *BufLintRequest.rules(),
141
    ]
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