• 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

80.95
/src/python/pants/backend/python/lint/ruff/format/rules.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from dataclasses import dataclass
2✔
5

6
from pants.backend.python.lint.ruff.common import RunRuffRequest, run_ruff
2✔
7
from pants.backend.python.lint.ruff.format.skip_field import SkipRuffFormatField
2✔
8
from pants.backend.python.lint.ruff.skip_field import SkipRuffField
2✔
9
from pants.backend.python.lint.ruff.subsystem import Ruff, RuffMode
2✔
10
from pants.backend.python.target_types import (
2✔
11
    InterpreterConstraintsField,
12
    PythonResolveField,
13
    PythonSourceField,
14
)
15
from pants.backend.python.util_rules import pex
2✔
16
from pants.core.goals.fmt import AbstractFmtRequest, FmtResult, FmtTargetsRequest
2✔
17
from pants.core.util_rules.partitions import PartitionerType
2✔
18
from pants.engine.platform import Platform
2✔
19
from pants.engine.rules import collect_rules, rule
2✔
20
from pants.engine.target import FieldSet, Target
2✔
21
from pants.util.logging import LogLevel
2✔
22
from pants.util.meta import classproperty
2✔
23

24

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

29
    source: PythonSourceField
2✔
30
    resolve: PythonResolveField
2✔
31
    interpreter_constraints: InterpreterConstraintsField
2✔
32

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

37

38
class RuffFormatRequest(FmtTargetsRequest):
2✔
39
    field_set_type = RuffFormatFieldSet
2✔
40
    tool_subsystem = Ruff  # type: ignore[assignment]
2✔
41
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
2✔
42

43
    @classproperty
2✔
44
    def tool_name(cls) -> str:
2✔
45
        return "ruff format"
×
46

47
    @classproperty
2✔
48
    def tool_id(self) -> str:
2✔
49
        return "ruff-format"
×
50

51

52
# Note - this function is kept separate because it is invoked from update_build_files.py, but
53
# not as a rule.
54
async def _run_ruff_fmt(
2✔
55
    request: AbstractFmtRequest.Batch,
56
    ruff: Ruff,
57
    platform: Platform,
58
) -> FmtResult:
59
    run_ruff_request = RunRuffRequest(
×
60
        snapshot=request.snapshot,
61
        mode=RuffMode.FORMAT,
62
    )
63
    result = await run_ruff(run_ruff_request, ruff, platform)
×
64
    return await FmtResult.create(request, result)
×
65

66

67
@rule(desc="Format with `ruff format`", level=LogLevel.DEBUG)
2✔
68
async def ruff_fmt(request: RuffFormatRequest.Batch, ruff: Ruff, platform: Platform) -> FmtResult:
2✔
69
    return await _run_ruff_fmt(request, ruff, platform)
×
70

71

72
def rules():
2✔
73
    return [
×
74
        *collect_rules(),
75
        *RuffFormatRequest.rules(),
76
        *pex.rules(),
77
    ]
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