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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

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

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

0.0
/src/python/pants/backend/python/lint/pyupgrade/rules.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from __future__ import annotations
×
4

UNCOV
5
import logging
×
UNCOV
6
from dataclasses import dataclass
×
7

UNCOV
8
from pants.backend.python.lint.pyupgrade.skip_field import SkipPyUpgradeField
×
UNCOV
9
from pants.backend.python.lint.pyupgrade.subsystem import PyUpgrade
×
UNCOV
10
from pants.backend.python.target_types import PythonSourceField
×
UNCOV
11
from pants.backend.python.util_rules import pex
×
UNCOV
12
from pants.backend.python.util_rules.pex import VenvPexProcess, create_venv_pex
×
UNCOV
13
from pants.core.goals.fix import FixResult, FixTargetsRequest
×
UNCOV
14
from pants.core.util_rules.partitions import PartitionerType
×
UNCOV
15
from pants.engine.intrinsics import execute_process
×
UNCOV
16
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
17
from pants.engine.target import FieldSet, Target
×
UNCOV
18
from pants.util.logging import LogLevel
×
UNCOV
19
from pants.util.strutil import pluralize, softwrap
×
20

UNCOV
21
logger = logging.getLogger(__name__)
×
22

23

UNCOV
24
@dataclass(frozen=True)
×
UNCOV
25
class PyUpgradeFieldSet(FieldSet):
×
UNCOV
26
    required_fields = (PythonSourceField,)
×
27

UNCOV
28
    source: PythonSourceField
×
29

UNCOV
30
    @classmethod
×
UNCOV
31
    def opt_out(cls, tgt: Target) -> bool:
×
32
        return tgt.get(SkipPyUpgradeField).value
×
33

34

UNCOV
35
class PyUpgradeRequest(FixTargetsRequest):
×
UNCOV
36
    field_set_type = PyUpgradeFieldSet
×
UNCOV
37
    tool_subsystem = PyUpgrade  # type: ignore[assignment]
×
UNCOV
38
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
×
39

40

UNCOV
41
@rule(desc="Fix with pyupgrade", level=LogLevel.DEBUG)
×
UNCOV
42
async def pyupgrade_fix(request: PyUpgradeRequest.Batch, pyupgrade: PyUpgrade) -> FixResult:
×
43
    pyupgrade_pex = await create_venv_pex(**implicitly(pyupgrade.to_pex_request()))
×
44

45
    # NB: Pyupgrade isn't idempotent, but eventually converges. So keep running until it stops
46
    # changing code. See https://github.com/asottile/pyupgrade/issues/703
47
    # (Technically we could not do this. It doesn't break Pants since the next run on the CLI would
48
    # use the new file with the new digest. However that isn't the UX we want for our users.)
49
    input_digest = request.snapshot.digest
×
50
    for _ in range(10):  # Give the loop an upper bound to guard against infinite runs
×
51
        result = await execute_process(
×
52
            **implicitly(
53
                VenvPexProcess(
54
                    pyupgrade_pex,
55
                    argv=(*pyupgrade.args, *request.files),
56
                    input_digest=input_digest,
57
                    output_files=request.files,
58
                    description=f"Run pyupgrade on {pluralize(len(request.files), 'file')}.",
59
                    level=LogLevel.DEBUG,
60
                )
61
            )
62
        )
63
        if input_digest == result.output_digest:
×
64
            # Nothing changed, either due to failure or because it is fixed
65
            break
×
66
        input_digest = result.output_digest
×
67
    else:
68
        logger.error(
×
69
            softwrap(
70
                """
71
                Pants ran Pyupgrade continuously on the code 10 times and it changed all 10.
72

73
                Pyupgrade is not idempotent, but should eventually converge. This is either a bug in
74
                Pyupgrade, or Pyupgrade is still trying to converge on fixed code.
75
                """
76
            )
77
        )
78

79
    return await FixResult.create(request, result)
×
80

81

UNCOV
82
def rules():
×
UNCOV
83
    return (
×
84
        *collect_rules(),
85
        *PyUpgradeRequest.rules(),
86
        *pex.rules(),
87
    )
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

© 2025 Coveralls, Inc