• 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.13
/src/python/pants/backend/python/lint/yapf/subsystem.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
import os.path
2✔
7
from collections.abc import Iterable
2✔
8

9
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
2✔
10
from pants.backend.python.target_types import ConsoleScript
2✔
11
from pants.core.goals.resolves import ExportableTool
2✔
12
from pants.core.util_rules.config_files import ConfigFilesRequest
2✔
13
from pants.engine.rules import collect_rules
2✔
14
from pants.engine.unions import UnionRule
2✔
15
from pants.option.option_types import ArgsListOption, BoolOption, FileOption, SkipOption
2✔
16
from pants.util.strutil import softwrap
2✔
17

18

19
class Yapf(PythonToolBase):
2✔
20
    options_scope = "yapf"
2✔
21
    name = "yapf"
2✔
22
    help_short = "A formatter for Python files (https://github.com/google/yapf)."
2✔
23

24
    default_main = ConsoleScript("yapf")
2✔
25
    default_requirements = ["yapf>=0.32.0,<1", "toml"]
2✔
26

27
    register_interpreter_constraints = True
2✔
28

29
    default_lockfile_resource = ("pants.backend.python.lint.yapf", "yapf.lock")
2✔
30

31
    skip = SkipOption("fmt", "lint")
2✔
32
    args = ArgsListOption(
2✔
33
        example="--no-local-style",
34
        extra_help=softwrap(
35
            """
36
            Certain arguments, specifically `--recursive`, `--in-place`, and
37
            `--parallel`, will be ignored because Pants takes care of finding
38
            all the relevant files and running the formatting in parallel.
39
            """
40
        ),
41
    )
42
    config = FileOption(
2✔
43
        default=None,
44
        advanced=True,
45
        help=lambda cls: softwrap(
46
            f"""
47
            Path to style file understood by yapf
48
            (https://github.com/google/yapf#formatting-style/).
49

50
            Setting this option will disable `[{cls.options_scope}].config_discovery`. Use
51
            this option if the config is located in a non-standard location.
52
            """
53
        ),
54
    )
55
    config_discovery = BoolOption(
2✔
56
        default=True,
57
        advanced=True,
58
        help=lambda cls: softwrap(
59
            f"""
60
            If true, Pants will include any relevant config files during
61
            runs (`.style.yapf`, `pyproject.toml`, and `setup.cfg`).
62

63
            Use `[{cls.options_scope}].config` instead if your config is in a
64
            non-standard location.
65
            """
66
        ),
67
    )
68

69
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
2✔
70
        # Refer to https://github.com/google/yapf#formatting-style.
71
        check_existence = []
×
72
        check_content = {}
×
73
        for d in ("", *dirs):
×
74
            check_existence.append(os.path.join(d, ".yapfignore"))
×
75
            check_content.update(
×
76
                {
77
                    os.path.join(d, "pyproject.toml"): b"[tool.yapf",
78
                    os.path.join(d, "setup.cfg"): b"[yapf]",
79
                    os.path.join(d, ".style.yapf"): b"[style]",
80
                }
81
            )
82

83
        return ConfigFilesRequest(
×
84
            specified=self.config,
85
            specified_option_name=f"[{self.options_scope}].config",
86
            discovery=self.config_discovery,
87
            check_existence=check_existence,
88
            check_content=check_content,
89
        )
90

91

92
def rules():
2✔
93
    return [
×
94
        *collect_rules(),
95
        UnionRule(ExportableTool, Yapf),
96
    ]
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