• 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

78.05
/src/python/pants/backend/python/lint/yapf/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 __future__ import annotations
2✔
5

6
from dataclasses import dataclass
2✔
7

8
from pants.backend.python.lint.yapf.skip_field import SkipYapfField
2✔
9
from pants.backend.python.lint.yapf.subsystem import Yapf
2✔
10
from pants.backend.python.target_types import PythonSourceField
2✔
11
from pants.backend.python.util_rules import pex
2✔
12
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
2✔
13
from pants.backend.python.util_rules.pex import VenvPexProcess, create_venv_pex
2✔
14
from pants.core.goals.fmt import AbstractFmtRequest, FmtResult, FmtTargetsRequest
2✔
15
from pants.core.util_rules.config_files import find_config_file
2✔
16
from pants.core.util_rules.partitions import PartitionerType
2✔
17
from pants.engine.fs import MergeDigests
2✔
18
from pants.engine.intrinsics import merge_digests
2✔
19
from pants.engine.process import execute_process_or_raise
2✔
20
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
2✔
21
from pants.engine.target import FieldSet, Target
2✔
22
from pants.util.logging import LogLevel
2✔
23
from pants.util.strutil import pluralize
2✔
24

25

26
@dataclass(frozen=True)
2✔
27
class YapfFieldSet(FieldSet):
2✔
28
    required_fields = (PythonSourceField,)
2✔
29

30
    source: PythonSourceField
2✔
31

32
    @classmethod
2✔
33
    def opt_out(cls, tgt: Target) -> bool:
2✔
34
        return tgt.get(SkipYapfField).value
×
35

36

37
class YapfRequest(FmtTargetsRequest):
2✔
38
    field_set_type = YapfFieldSet
2✔
39
    tool_subsystem = Yapf  # type: ignore[assignment]
2✔
40
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
2✔
41

42

43
async def _run_yapf(
2✔
44
    request: AbstractFmtRequest.Batch,
45
    yapf: Yapf,
46
    interpreter_constraints: InterpreterConstraints | None = None,
47
) -> FmtResult:
48
    yapf_pex_get = create_venv_pex(
×
49
        **implicitly(yapf.to_pex_request(interpreter_constraints=interpreter_constraints))
50
    )
51
    config_files_get = find_config_file(yapf.config_request(request.snapshot.dirs))
×
52
    yapf_pex, config_files = await concurrently(yapf_pex_get, config_files_get)
×
53

54
    input_digest = await merge_digests(
×
55
        MergeDigests((request.snapshot.digest, config_files.snapshot.digest))
56
    )
57
    result = await execute_process_or_raise(
×
58
        **implicitly(
59
            VenvPexProcess(
60
                yapf_pex,
61
                argv=(
62
                    *yapf.args,
63
                    "--in-place",
64
                    *(("--style", yapf.config) if yapf.config else ()),
65
                    *request.files,
66
                ),
67
                input_digest=input_digest,
68
                output_files=request.files,
69
                description=f"Run yapf on {pluralize(len(request.files), 'file')}.",
70
                level=LogLevel.DEBUG,
71
            )
72
        )
73
    )
74
    return await FmtResult.create(request, result)
×
75

76

77
@rule(desc="Format with yapf", level=LogLevel.DEBUG)
2✔
78
async def yapf_fmt(request: YapfRequest.Batch, yapf: Yapf) -> FmtResult:
2✔
79
    return await _run_yapf(request, yapf)
×
80

81

82
def rules():
2✔
83
    return (
×
84
        *collect_rules(),
85
        *YapfRequest.rules(),
86
        *pex.rules(),
87
    )
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