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

pantsbuild / pants / 19381742489

15 Nov 2025 12:52AM UTC coverage: 49.706% (-30.6%) from 80.29%
19381742489

Pull #22890

github

web-flow
Merge d961abf79 into 42e1ebd41
Pull Request #22890: Updated all python subsystem constraints to 3.14

4 of 5 new or added lines in 5 files covered. (80.0%)

14659 existing lines in 485 files now uncovered.

31583 of 63540 relevant lines covered (49.71%)

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

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

24

25
FmtResult = FixResult
2✔
26

27

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

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

39

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

46

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

53

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

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

84

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

89

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

94

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

99

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

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