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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

0.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

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
import os.path
×
UNCOV
7
from collections.abc import Iterable
×
UNCOV
8
from dataclasses import dataclass
×
9

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

26

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

UNCOV
31
    source: PythonSourceField
×
UNCOV
32
    interpreter_constraints: InterpreterConstraintsField
×
UNCOV
33
    resolve: PythonResolveField
×
34

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

39

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

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

UNCOV
52
    register_interpreter_constraints = True
×
53

UNCOV
54
    default_lockfile_resource = ("pants.backend.python.lint.black", "black.lock")
×
55

UNCOV
56
    skip = SkipOption("fmt", "lint")
×
UNCOV
57
    args = ArgsListOption(example="--target-version=py37 --quiet")
×
UNCOV
58
    config = FileOption(
×
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
    )
UNCOV
71
    config_discovery = BoolOption(
×
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

UNCOV
84
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
×
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

UNCOV
96
def rules():
×
UNCOV
97
    return [
×
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