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

pantsbuild / pants / 20836862798

09 Jan 2026 12:31AM UTC coverage: 43.231% (-37.0%) from 80.274%
20836862798

Pull #22992

github

web-flow
Merge 0983a6a7c into 0d471f924
Pull Request #22992: feat(engine): log elapsed time for completed workunits

26137 of 60459 relevant lines covered (43.23%)

0.86 hits per line

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

91.23
/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
2✔
5

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

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

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

29

30
FmtResult = FixResult
2✔
31

32

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

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

44

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

51

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

58

59
class FmtSubsystem(GoalSubsystem):
2✔
60
    name = "fmt"
2✔
61
    help = softwrap(
2✔
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
2✔
83
    def activated(cls, union_membership: UnionMembership) -> bool:
2✔
84
        return AbstractFmtRequest in union_membership
×
85

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

89

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

94

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

99

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

104

105
@goal_rule
2✔
106
async def fmt(
2✔
107
    console: Console,
108
    specs: Specs,
109
    fmt_subsystem: FmtSubsystem,
110
    workspace: Workspace,
111
    union_membership: UnionMembership,
112
) -> Fmt:
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():
2✔
132
    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