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

pantsbuild / pants / 25443604553

06 May 2026 03:05PM UTC coverage: 92.879% (-0.04%) from 92.915%
25443604553

push

github

web-flow
[pants_ng] Scaffolding for a pants_ng mode. (#23319)

In this mode the command line is parsed as an
NG invocation, and dispatched appropriately.

Of course at the moment there are no
implementations to dispatch to. That will follow.

This does expose a new option, `pants_ng` to users. 
There is a big warning not to set it, but we're not trying
to hide that we're working on a new thing, so I am
comfortable with this.

25 of 76 new or added lines in 9 files covered. (32.89%)

1294 existing lines in 76 files now uncovered.

92234 of 99306 relevant lines covered (92.88%)

4.05 hits per line

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

91.11
/src/python/pants/backend/codegen/protobuf/lint/buf/format_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
1✔
4

UNCOV
5
from pants.backend.codegen.protobuf.lint.buf.skip_field import SkipBufFormatField
1✔
UNCOV
6
from pants.backend.codegen.protobuf.lint.buf.subsystem import BufSubsystem
1✔
UNCOV
7
from pants.backend.codegen.protobuf.target_types import (
1✔
8
    ProtobufDependenciesField,
9
    ProtobufSourceField,
10
)
UNCOV
11
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest, Partitions
1✔
UNCOV
12
from pants.core.util_rules.external_tool import download_external_tool
1✔
UNCOV
13
from pants.core.util_rules.system_binaries import (
1✔
14
    BinaryShimsRequest,
15
    DiffBinary,
16
    create_binary_shims,
17
)
UNCOV
18
from pants.engine.fs import MergeDigests
1✔
UNCOV
19
from pants.engine.intrinsics import merge_digests
1✔
UNCOV
20
from pants.engine.platform import Platform
1✔
UNCOV
21
from pants.engine.process import Process, execute_process_or_raise
1✔
UNCOV
22
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
1✔
UNCOV
23
from pants.engine.target import FieldSet, Target
1✔
UNCOV
24
from pants.util.logging import LogLevel
1✔
UNCOV
25
from pants.util.meta import classproperty
1✔
UNCOV
26
from pants.util.strutil import pluralize
1✔
27

28

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

33
    sources: ProtobufSourceField
34
    dependencies: ProtobufDependenciesField
35

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

40

UNCOV
41
class BufFormatRequest(FmtTargetsRequest):
1✔
UNCOV
42
    field_set_type = BufFieldSet
1✔
UNCOV
43
    tool_subsystem = BufSubsystem  # type: ignore[assignment]
1✔
44

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

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

53

UNCOV
54
@rule
1✔
UNCOV
55
async def partition_buf(
1✔
56
    request: BufFormatRequest.PartitionRequest, buf: BufSubsystem
57
) -> Partitions:
58
    return (
×
59
        Partitions()
60
        if buf.format_skip
61
        else Partitions.single_partition(
62
            field_set.sources.file_path for field_set in request.field_sets
63
        )
64
    )
65

66

UNCOV
67
@rule(desc="Format with buf format", level=LogLevel.DEBUG)
1✔
UNCOV
68
async def run_buf_format(
1✔
69
    request: BufFormatRequest.Batch, buf: BufSubsystem, diff_binary: DiffBinary, platform: Platform
70
) -> FmtResult:
UNCOV
71
    download_buf_get = download_external_tool(buf.get_request(platform))
1✔
UNCOV
72
    binary_shims_get = create_binary_shims(
1✔
73
        BinaryShimsRequest.for_paths(
74
            diff_binary,
75
            rationale="run `buf format`",
76
        ),
77
        **implicitly(),
78
    )
UNCOV
79
    downloaded_buf, binary_shims = await concurrently(download_buf_get, binary_shims_get)
1✔
80

UNCOV
81
    input_digest = await merge_digests(
1✔
82
        MergeDigests((request.snapshot.digest, downloaded_buf.digest))
83
    )
84

UNCOV
85
    argv = [
1✔
86
        downloaded_buf.exe,
87
        "format",
88
        "-w",
89
        *buf.format_args,
90
        "--path",
91
        ",".join(request.files),
92
    ]
UNCOV
93
    result = await execute_process_or_raise(
1✔
94
        **implicitly(
95
            Process(
96
                argv=argv,
97
                input_digest=input_digest,
98
                output_files=request.files,
99
                description=f"Run buf format on {pluralize(len(request.files), 'file')}.",
100
                level=LogLevel.DEBUG,
101
                env={"PATH": binary_shims.path_component},
102
                immutable_input_digests=binary_shims.immutable_input_digests,
103
            )
104
        ),
105
    )
UNCOV
106
    return await FmtResult.create(request, result)
1✔
107

108

UNCOV
109
def rules():
1✔
UNCOV
110
    return [
1✔
111
        *collect_rules(),
112
        *BufFormatRequest.rules(),
113
    ]
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