• 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/core/goals/fmt.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 logging
×
UNCOV
7
from collections.abc import Iterable
×
8

UNCOV
9
from pants.base.specs import Specs
×
UNCOV
10
from pants.core.goals.fix import AbstractFixRequest, FixFilesRequest, FixResult, FixTargetsRequest
×
UNCOV
11
from pants.core.goals.fix import Partitions as Partitions  # re-export
×
UNCOV
12
from pants.core.goals.fix import _do_fix
×
UNCOV
13
from pants.core.goals.multi_tool_goal_helper import BatchSizeOption, OnlyOption
×
UNCOV
14
from pants.engine.console import Console
×
UNCOV
15
from pants.engine.fs import Workspace
×
UNCOV
16
from pants.engine.goal import Goal, GoalSubsystem
×
UNCOV
17
from pants.engine.rules import collect_rules, goal_rule, implicitly, rule
×
UNCOV
18
from pants.engine.unions import UnionMembership, UnionRule, union
×
UNCOV
19
from pants.util.docutil import doc_url
×
UNCOV
20
from pants.util.strutil import softwrap
×
21

UNCOV
22
logger = logging.getLogger(__name__)
×
23

24

UNCOV
25
FmtResult = FixResult
×
26

27

UNCOV
28
@union
×
UNCOV
29
class AbstractFmtRequest(AbstractFixRequest):
×
UNCOV
30
    is_formatter = True
×
UNCOV
31
    is_fixer = False
×
32

UNCOV
33
    @classmethod
×
UNCOV
34
    def _get_rules(cls) -> Iterable[UnionRule]:
×
UNCOV
35
        yield from super()._get_rules()
×
UNCOV
36
        yield UnionRule(AbstractFmtRequest, cls)
×
UNCOV
37
        yield UnionRule(AbstractFmtRequest.Batch, cls.Batch)
×
38

39

UNCOV
40
class FmtTargetsRequest(AbstractFmtRequest, FixTargetsRequest):
×
UNCOV
41
    @classmethod
×
UNCOV
42
    def _get_rules(cls) -> Iterable:
×
UNCOV
43
        yield from super()._get_rules()
×
UNCOV
44
        yield UnionRule(FmtTargetsRequest.PartitionRequest, cls.PartitionRequest)
×
45

46

UNCOV
47
class FmtFilesRequest(AbstractFmtRequest, FixFilesRequest):
×
UNCOV
48
    @classmethod
×
UNCOV
49
    def _get_rules(cls) -> Iterable:
×
UNCOV
50
        yield from super()._get_rules()
×
UNCOV
51
        yield UnionRule(FmtFilesRequest.PartitionRequest, cls.PartitionRequest)
×
52

53

UNCOV
54
class FmtSubsystem(GoalSubsystem):
×
UNCOV
55
    name = "fmt"
×
UNCOV
56
    help = softwrap(
×
57
        f"""
58
        Autoformat source code.
59

60
        This goal runs tools that make 'syntactic' changes to source code, where the meaning of the
61
        code doesn't (usually) change.
62

63
        See also:
64

65
        - [The `fix` goal]({doc_url("reference/goals/fix")}) will run code-editing tools that may make semantic
66
          changes, not just syntactic ones.
67

68
        - [The `lint` goal]({doc_url("reference/goals/lint")}) will validate code is formatted, by running these
69
          formatters and checking there's no change.
70

71
        - Documentation about formatters for various ecosystems, such as:
72
          [Python]({doc_url("docs/python/overview/linters-and-formatters")}), [Go]({doc_url("docs/go#gofmt")}),
73
          [JVM]({doc_url("jvm/java-and-scala#lint-and-format")}), [Shell]({doc_url("docs/shell#shfmt-autoformatter")}).
74
        """
75
    )
76

UNCOV
77
    @classmethod
×
UNCOV
78
    def activated(cls, union_membership: UnionMembership) -> bool:
×
79
        return AbstractFmtRequest in union_membership
×
80

UNCOV
81
    only = OnlyOption("formatter", "isort", "shfmt")
×
UNCOV
82
    batch_size = BatchSizeOption(uppercase="Formatter", lowercase="formatter")
×
83

84

UNCOV
85
class Fmt(Goal):
×
UNCOV
86
    subsystem_cls = FmtSubsystem
×
UNCOV
87
    environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY
×
88

89

UNCOV
90
@rule(polymorphic=True)
×
UNCOV
91
async def partition_targets(req: FmtTargetsRequest.PartitionRequest) -> Partitions:
×
92
    raise NotImplementedError()
×
93

94

UNCOV
95
@rule(polymorphic=True)
×
UNCOV
96
async def partition_files(req: FmtFilesRequest.PartitionRequest) -> Partitions:
×
97
    raise NotImplementedError()
×
98

99

UNCOV
100
@goal_rule
×
UNCOV
101
async def fmt(
×
102
    console: Console,
103
    specs: Specs,
104
    fmt_subsystem: FmtSubsystem,
105
    workspace: Workspace,
106
    union_membership: UnionMembership,
107
) -> Fmt:
108
    return await _do_fix(
×
109
        union_membership.get(AbstractFmtRequest),
110
        union_membership.get(FmtTargetsRequest.PartitionRequest),
111
        union_membership.get(FmtFilesRequest.PartitionRequest),
112
        Fmt,
113
        fmt_subsystem,  # type: ignore[arg-type]
114
        specs,
115
        workspace,
116
        console,
117
        lambda request_type: partition_targets(
118
            **implicitly({request_type: FmtTargetsRequest.PartitionRequest})
119
        ),
120
        lambda request_type: partition_files(
121
            **implicitly({request_type: FmtFilesRequest.PartitionRequest})
122
        ),
123
    )
124

125

UNCOV
126
def rules():
×
UNCOV
127
    return collect_rules()
×
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