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

pantsbuild / pants / 20328535594

18 Dec 2025 06:46AM UTC coverage: 57.969% (-22.3%) from 80.295%
20328535594

Pull #22954

github

web-flow
Merge ccc9c5409 into 407284c67
Pull Request #22954: free up disk space in runner image

39083 of 67421 relevant lines covered (57.97%)

0.91 hits per line

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

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

4
from dataclasses import dataclass
×
5

6
from pants.backend.shell.lint.shfmt.skip_field import SkipShfmtField
×
7
from pants.backend.shell.lint.shfmt.subsystem import Shfmt
×
8
from pants.backend.shell.target_types import ShellSourceField
×
9
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
×
10
from pants.core.goals.resolves import ExportableTool
×
11
from pants.core.util_rules.config_files import find_config_file
×
12
from pants.core.util_rules.external_tool import download_external_tool
×
13
from pants.core.util_rules.partitions import PartitionerType
×
14
from pants.engine.fs import MergeDigests
×
15
from pants.engine.intrinsics import merge_digests
×
16
from pants.engine.platform import Platform
×
17
from pants.engine.process import Process, execute_process_or_raise
×
18
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
×
19
from pants.engine.target import FieldSet, Target
×
20
from pants.engine.unions import UnionRule
×
21
from pants.util.logging import LogLevel
×
22
from pants.util.strutil import pluralize
×
23

24

25
@dataclass(frozen=True)
×
26
class ShfmtFieldSet(FieldSet):
×
27
    required_fields = (ShellSourceField,)
×
28

29
    sources: ShellSourceField
×
30

31
    @classmethod
×
32
    def opt_out(cls, tgt: Target) -> bool:
×
33
        return tgt.get(SkipShfmtField).value
×
34

35

36
class ShfmtRequest(FmtTargetsRequest):
×
37
    field_set_type = ShfmtFieldSet
×
38
    tool_subsystem = Shfmt  # type: ignore[assignment]
×
39
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
×
40

41

42
@rule(desc="Format with shfmt", level=LogLevel.DEBUG)
×
43
async def shfmt_fmt(request: ShfmtRequest.Batch, shfmt: Shfmt, platform: Platform) -> FmtResult:
×
44
    download_shfmt_get = download_external_tool(shfmt.get_request(platform))
×
45
    config_files_get = find_config_file(shfmt.config_request(request.snapshot.dirs))
×
46
    downloaded_shfmt, config_files = await concurrently(download_shfmt_get, config_files_get)
×
47
    input_digest = await merge_digests(
×
48
        MergeDigests(
49
            (request.snapshot.digest, downloaded_shfmt.digest, config_files.snapshot.digest)
50
        )
51
    )
52

53
    result = await execute_process_or_raise(
×
54
        **implicitly(
55
            Process(
56
                argv=(
57
                    downloaded_shfmt.exe,
58
                    "-l",
59
                    "-w",
60
                    *shfmt.args,
61
                    *request.files,
62
                ),
63
                input_digest=input_digest,
64
                output_files=request.files,
65
                description=f"Run shfmt on {pluralize(len(request.files), 'file')}.",
66
                level=LogLevel.DEBUG,
67
            )
68
        )
69
    )
70
    return await FmtResult.create(request, result)
×
71

72

73
def rules():
×
74
    return [
×
75
        *collect_rules(),
76
        *ShfmtRequest.rules(),
77
        UnionRule(ExportableTool, Shfmt),
78
    ]
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