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

pantsbuild / pants / 19000741080

01 Nov 2025 06:16PM UTC coverage: 80.3% (+0.3%) from 80.004%
19000741080

Pull #22837

github

web-flow
Merge 51f49bc90 into da3fb359e
Pull Request #22837: Updated Treesitter dependencies

77994 of 97128 relevant lines covered (80.3%)

3.35 hits per line

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

92.68
/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
10✔
5

6
import os.path
10✔
7
from collections.abc import Iterable
10✔
8
from dataclasses import dataclass
10✔
9

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

26

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

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

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

39

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

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

52
    register_interpreter_constraints = True
10✔
53

54
    default_lockfile_resource = ("pants.backend.python.lint.black", "black.lock")
10✔
55

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

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

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

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

95

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

© 2025 Coveralls, Inc