• 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

90.0
/src/python/pants/backend/python/lint/black/subsystem.py
1
# Copyright 2019 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
from dataclasses import dataclass
2✔
9

10
from pants.backend.python.lint.black.skip_field import SkipBlackField
2✔
11
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
2✔
12
from pants.backend.python.target_types import (
2✔
13
    ConsoleScript,
14
    InterpreterConstraintsField,
15
    PythonResolveField,
16
    PythonSourceField,
17
)
18
from pants.core.goals.resolves import ExportableTool
2✔
19
from pants.core.util_rules.config_files import ConfigFilesRequest
2✔
20
from pants.engine.rules import collect_rules
2✔
21
from pants.engine.target import FieldSet, Target
2✔
22
from pants.engine.unions import UnionRule
2✔
23
from pants.option.option_types import ArgsListOption, BoolOption, FileOption, SkipOption
2✔
24
from pants.util.strutil import softwrap
2✔
25

26

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

31
    source: PythonSourceField
2✔
32
    interpreter_constraints: InterpreterConstraintsField
2✔
33
    resolve: PythonResolveField
2✔
34

35
    @classmethod
2✔
36
    def opt_out(cls, tgt: Target) -> bool:
2✔
37
        return tgt.get(SkipBlackField).value
×
38

39

40
class Black(PythonToolBase):
2✔
41
    options_scope = "black"
2✔
42
    name = "Black"
2✔
43
    help_short = "The Black Python code formatter (https://black.readthedocs.io/)."
2✔
44

45
    default_main = ConsoleScript("black")
2✔
46
    default_requirements = [
2✔
47
        "black>=22.6.0,<25",
48
        'typing-extensions>=3.10.0.0; python_version < "3.10"',
49
    ]
50

51
    register_interpreter_constraints = True
2✔
52

53
    default_lockfile_resource = ("pants.backend.python.lint.black", "black.lock")
2✔
54

55
    skip = SkipOption("fmt", "lint")
2✔
56
    args = ArgsListOption(example="--target-version=py37 --quiet")
2✔
57
    config = FileOption(
2✔
58
        default=None,
59
        advanced=True,
60
        help=lambda cls: softwrap(
61
            f"""
62
            Path to a TOML config file understood by Black
63
            (https://github.com/psf/black#configuration-format).
64

65
            Setting this option will disable `[{cls.options_scope}].config_discovery`. Use
66
            this option if the config is located in a non-standard location.
67
            """
68
        ),
69
    )
70
    config_discovery = BoolOption(
2✔
71
        default=True,
72
        advanced=True,
73
        help=lambda cls: softwrap(
74
            f"""
75
            If true, Pants will include any relevant pyproject.toml config files during runs.
76

77
            Use `[{cls.options_scope}].config` instead if your config is in a
78
            non-standard location.
79
            """
80
        ),
81
    )
82

83
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
2✔
84
        # Refer to https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#where-black-looks-for-the-file
85
        # for how Black discovers config.
86
        candidates = {os.path.join(d, "pyproject.toml"): b"[tool.black]" for d in ("", *dirs)}
×
87
        return ConfigFilesRequest(
×
88
            specified=self.config,
89
            specified_option_name=f"[{self.options_scope}].config",
90
            discovery=self.config_discovery,
91
            check_content=candidates,
92
        )
93

94

95
def rules():
2✔
96
    return [
×
97
        *collect_rules(),
98
        UnionRule(ExportableTool, Black),
99
    ]
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