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

pantsbuild / pants / 19572556425

21 Nov 2025 01:50PM UTC coverage: 80.295% (+0.007%) from 80.288%
19572556425

Pull #22906

github

web-flow
Merge c59ca89b1 into 70dc9fe34
Pull Request #22906: Update Coursier default version to v2.1.24

3 of 3 new or added lines in 2 files covered. (100.0%)

294 existing lines in 12 files now uncovered.

78385 of 97621 relevant lines covered (80.3%)

3.36 hits per line

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

93.1
/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
12✔
5

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

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

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

24

25
FmtResult = FixResult
12✔
26

27

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

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

39

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

46

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

53

54
class FmtSubsystem(GoalSubsystem):
12✔
55
    name = "fmt"
12✔
56
    help = softwrap(
12✔
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
12✔
78
    def activated(cls, union_membership: UnionMembership) -> bool:
12✔
UNCOV
79
        return AbstractFmtRequest in union_membership
×
80

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

84

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

89

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

94

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

99

100
@goal_rule
12✔
101
async def fmt(
12✔
102
    console: Console,
103
    specs: Specs,
104
    fmt_subsystem: FmtSubsystem,
105
    workspace: Workspace,
106
    union_membership: UnionMembership,
107
) -> Fmt:
UNCOV
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

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