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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

91.38
/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
3✔
5

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

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

22
logger = logging.getLogger(__name__)
3✔
23

24

25
FmtResult = FixResult
3✔
26

27

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

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

39

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

46

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

53

54
class FmtSubsystem(GoalSubsystem):
3✔
55
    name = "fmt"
3✔
56
    help = softwrap(
3✔
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

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

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

84

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

89

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

94

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

99

100
@goal_rule
3✔
101
async def fmt(
3✔
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,
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

126
def rules():
3✔
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