• 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/ruff/common.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
import os
×
UNCOV
4
from dataclasses import dataclass
×
UNCOV
5
from typing import assert_never
×
6

UNCOV
7
from pants.backend.python.lint.ruff.subsystem import Ruff, RuffMode
×
UNCOV
8
from pants.core.goals.lint import REPORT_DIR
×
UNCOV
9
from pants.core.util_rules.config_files import find_config_file
×
UNCOV
10
from pants.core.util_rules.external_tool import download_external_tool
×
UNCOV
11
from pants.engine.fs import CreateDigest, Directory, MergeDigests
×
UNCOV
12
from pants.engine.internals.native_engine import Snapshot
×
UNCOV
13
from pants.engine.internals.selectors import concurrently
×
UNCOV
14
from pants.engine.intrinsics import create_digest, execute_process, merge_digests
×
UNCOV
15
from pants.engine.platform import Platform
×
UNCOV
16
from pants.engine.process import FallibleProcessResult, Process
×
UNCOV
17
from pants.engine.rules import implicitly
×
UNCOV
18
from pants.util.logging import LogLevel
×
UNCOV
19
from pants.util.strutil import pluralize
×
20

21

UNCOV
22
@dataclass(frozen=True)
×
UNCOV
23
class RunRuffRequest:
×
24
    snapshot: Snapshot
25
    mode: RuffMode
26

27

UNCOV
28
async def run_ruff(
×
29
    request: RunRuffRequest,
30
    ruff: Ruff,
31
    platform: Platform,
32
) -> FallibleProcessResult:
33
    ruff_tool_get = download_external_tool(ruff.get_request(platform))
×
34
    config_files_get = find_config_file(ruff.config_request(request.snapshot.dirs))
×
35
    # Ensure that the empty report dir exists.
36
    report_directory_digest_get = create_digest(CreateDigest([Directory(REPORT_DIR)]))
×
37

38
    ruff_tool, config_files, report_directory = await concurrently(
×
39
        ruff_tool_get, config_files_get, report_directory_digest_get
40
    )
41

42
    input_digest = await merge_digests(
×
43
        MergeDigests(
44
            (
45
                request.snapshot.digest,
46
                config_files.snapshot.digest,
47
                report_directory,
48
            )
49
        ),
50
    )
51

52
    conf_args = [f"--config={ruff.config}"] if ruff.config else []
×
53

54
    extra_initial_args: tuple[str, ...] = ()
×
55
    if request.mode is RuffMode.FORMAT:
×
56
        extra_initial_args = ("format",)
×
57
    elif request.mode is RuffMode.FIX:
×
58
        extra_initial_args = ("check", "--fix")
×
59
    elif request.mode is RuffMode.LINT:
×
60
        extra_initial_args = ("check",)
×
61
    else:
62
        assert_never(request.mode)
×
63

64
    # `--force-exclude` applies file excludes from config to files provided explicitly
65
    # The format argument must be passed before force-exclude if Ruff is used for formatting.
66
    # For other cases, the flags should work the same regardless of the order.
67
    initial_args = extra_initial_args + ("--force-exclude",)
×
68

69
    immutable_input_key = "__ruff_tool"
×
70
    exe_path = os.path.join(immutable_input_key, ruff_tool.exe)
×
71

72
    result = await execute_process(
×
73
        Process(
74
            argv=(exe_path, *initial_args, *conf_args, *ruff.args, *request.snapshot.files),
75
            input_digest=input_digest,
76
            immutable_input_digests={immutable_input_key: ruff_tool.digest},
77
            output_files=request.snapshot.files,
78
            output_directories=(REPORT_DIR,) if request.mode is RuffMode.LINT else (),
79
            description=f"Run ruff {' '.join(initial_args)} on {pluralize(len(request.snapshot.files), 'file')}.",
80
            level=LogLevel.DEBUG,
81
        ),
82
        **implicitly(),
83
    )
84
    return result
×
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