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

pantsbuild / pants / 20632486505

01 Jan 2026 04:21AM UTC coverage: 43.231% (-37.1%) from 80.281%
20632486505

Pull #22962

github

web-flow
Merge 08d5c63b0 into f52ab6675
Pull Request #22962: Bump the gha-deps group across 1 directory with 6 updates

26122 of 60424 relevant lines covered (43.23%)

0.86 hits per line

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

0.0
/src/python/pants/backend/cc/lint/clangformat/rules.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
×
5

6
import logging
×
7
from collections.abc import Iterable
×
8
from dataclasses import dataclass
×
9

10
from pants.backend.cc.lint.clangformat.subsystem import ClangFormat
×
11
from pants.backend.cc.target_types import CCSourceField
×
12
from pants.backend.python.util_rules.pex import PexProcess, create_pex
×
13
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
×
14
from pants.core.util_rules.config_files import find_config_file
×
15
from pants.core.util_rules.partitions import PartitionerType
×
16
from pants.engine.fs import MergeDigests
×
17
from pants.engine.intrinsics import merge_digests
×
18
from pants.engine.process import fallible_to_exec_result_or_raise
×
19
from pants.engine.rules import Rule, collect_rules, concurrently, implicitly, rule
×
20
from pants.engine.target import FieldSet
×
21
from pants.engine.unions import UnionRule
×
22
from pants.util.logging import LogLevel
×
23
from pants.util.strutil import pluralize
×
24

25
logger = logging.getLogger(__name__)
×
26

27

28
@dataclass(frozen=True)
×
29
class ClangFormatFmtFieldSet(FieldSet):
×
30
    required_fields = (CCSourceField,)
×
31

32
    sources: CCSourceField
×
33

34

35
class ClangFormatRequest(FmtTargetsRequest):
×
36
    field_set_type = ClangFormatFmtFieldSet
×
37
    tool_subsystem = ClangFormat  # type: ignore[assignment]
×
38
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
×
39

40

41
@rule(level=LogLevel.DEBUG)
×
42
async def clangformat_fmt(request: ClangFormatRequest.Batch, clangformat: ClangFormat) -> FmtResult:
×
43
    clangformat_pex, config_files = await concurrently(
×
44
        create_pex(clangformat.to_pex_request()),
45
        find_config_file(clangformat.config_request(request.snapshot.dirs)),
46
    )
47

48
    # Merge source files, config files, and clang-format pex process
49
    input_digest = await merge_digests(
×
50
        MergeDigests(
51
            [request.snapshot.digest, config_files.snapshot.digest, clangformat_pex.digest]
52
        )
53
    )
54

55
    argv = (
×
56
        "--style=file",  # Look for .clang-format files
57
        "--fallback-style=webkit",  # Use WebKit if there is no config file
58
        "-i",  # In-place edits
59
        "--Werror",  # Formatting warnings as errors
60
        *clangformat.args,  # User-added arguments
61
        *request.files,
62
    )
63
    result = await fallible_to_exec_result_or_raise(
×
64
        **implicitly(
65
            PexProcess(
66
                clangformat_pex,
67
                argv=argv,
68
                input_digest=input_digest,
69
                output_files=request.files,
70
                description=f"Run clang-format on {pluralize(len(request.files), 'file')}.",
71
                level=LogLevel.DEBUG,
72
            )
73
        ),
74
    )
75

76
    return await FmtResult.create(request, result)
×
77

78

79
def rules() -> Iterable[Rule | UnionRule]:
×
80
    return (
×
81
        *collect_rules(),
82
        *ClangFormatRequest.rules(),
83
    )
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