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

pantsbuild / pants / 26260209689

21 May 2026 11:59PM UTC coverage: 75.453% (-15.7%) from 91.156%
26260209689

Pull #23365

github

web-flow
Merge 5fe873b58 into 7ea655ba0
Pull Request #23365: uv.lock -> pex optimization

5 of 16 new or added lines in 1 file covered. (31.25%)

10118 existing lines in 378 files now uncovered.

54669 of 72454 relevant lines covered (75.45%)

2.31 hits per line

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

92.98
/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

4
from __future__ import annotations
5✔
5

6
import logging
5✔
7
from collections.abc import Iterable
5✔
8

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

27
logger = logging.getLogger(__name__)
5✔
28

29

30
FmtResult = FixResult
5✔
31

32

33
@union
5✔
34
class AbstractFmtRequest(AbstractFixRequest):
5✔
35
    is_formatter = True
5✔
36
    is_fixer = False
5✔
37

38
    @classmethod
5✔
39
    def _get_rules(cls) -> Iterable[UnionRule]:
5✔
40
        yield from super()._get_rules()
5✔
41
        yield UnionRule(AbstractFmtRequest, cls)
5✔
42
        yield UnionRule(AbstractFmtRequest.Batch, cls.Batch)
5✔
43

44

45
class FmtTargetsRequest(AbstractFmtRequest, FixTargetsRequest):
5✔
46
    @classmethod
5✔
47
    def _get_rules(cls) -> Iterable:
5✔
48
        yield from super()._get_rules()
5✔
49
        yield UnionRule(FmtTargetsRequest.PartitionRequest, cls.PartitionRequest)
5✔
50

51

52
class FmtFilesRequest(AbstractFmtRequest, FixFilesRequest):
5✔
53
    @classmethod
5✔
54
    def _get_rules(cls) -> Iterable:
5✔
55
        yield from super()._get_rules()
4✔
56
        yield UnionRule(FmtFilesRequest.PartitionRequest, cls.PartitionRequest)
4✔
57

58

59
class FmtSubsystem(GoalSubsystem):
5✔
60
    name = "fmt"
5✔
61
    help = softwrap(
5✔
62
        f"""
63
        Autoformat source code.
64

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

68
        See also:
69

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

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

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

82
    @classmethod
5✔
83
    def activated(cls, union_membership: UnionMembership) -> bool:
5✔
84
        return AbstractFmtRequest in union_membership
×
85

86
    only = OnlyOption("formatter", "isort", "shfmt")
5✔
87
    batch_size = BatchSizeOption(uppercase="Formatter", lowercase="formatter")
5✔
88

89

90
class Fmt(Goal):
5✔
91
    subsystem_cls = FmtSubsystem
5✔
92
    environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY
5✔
93

94

95
@rule(polymorphic=True)
5✔
96
async def partition_targets(req: FmtTargetsRequest.PartitionRequest) -> Partitions:
5✔
97
    raise NotImplementedError()
×
98

99

100
@rule(polymorphic=True)
5✔
101
async def partition_files(req: FmtFilesRequest.PartitionRequest) -> Partitions:
5✔
102
    raise NotImplementedError()
×
103

104

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

130

131
def rules():
5✔
132
    return collect_rules()
1✔
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