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

pantsbuild / pants / 22285099215

22 Feb 2026 08:52PM UTC coverage: 75.854% (-17.1%) from 92.936%
22285099215

Pull #23121

github

web-flow
Merge c7299df9c into ba8359840
Pull Request #23121: fix issue with optional fields in dependency validator

28 of 29 new or added lines in 2 files covered. (96.55%)

11174 existing lines in 400 files now uncovered.

53694 of 70786 relevant lines covered (75.85%)

1.88 hits per line

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

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

5
from dataclasses import dataclass
1✔
6

7
from pants.backend.python.lint.isort.skip_field import SkipIsortField
1✔
8
from pants.backend.python.lint.isort.subsystem import Isort
1✔
9
from pants.backend.python.target_types import PythonSourceField
1✔
10
from pants.backend.python.util_rules import pex
1✔
11
from pants.backend.python.util_rules.pex import (
1✔
12
    VenvPexProcess,
13
    create_venv_pex,
14
    determine_venv_pex_resolve_info,
15
)
16
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
1✔
17
from pants.core.util_rules.config_files import find_config_file
1✔
18
from pants.core.util_rules.partitions import PartitionerType
1✔
19
from pants.engine.fs import MergeDigests
1✔
20
from pants.engine.intrinsics import merge_digests
1✔
21
from pants.engine.process import ProcessExecutionFailure, execute_process_or_raise
1✔
22
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
1✔
23
from pants.engine.target import FieldSet, Target
1✔
24
from pants.option.global_options import KeepSandboxes
1✔
25
from pants.util.logging import LogLevel
1✔
26
from pants.util.strutil import pluralize
1✔
27

28

29
@dataclass(frozen=True)
1✔
30
class IsortFieldSet(FieldSet):
1✔
31
    required_fields = (PythonSourceField,)
1✔
32

33
    source: PythonSourceField
1✔
34

35
    @classmethod
1✔
36
    def opt_out(cls, tgt: Target) -> bool:
1✔
37
        return tgt.get(SkipIsortField).value
×
38

39

40
class IsortRequest(FmtTargetsRequest):
1✔
41
    field_set_type = IsortFieldSet
1✔
42
    tool_subsystem = Isort  # type: ignore[assignment]
1✔
43
    partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION
1✔
44

45

46
def generate_argv(
1✔
47
    source_files: tuple[str, ...], isort: Isort, *, is_isort5: bool
48
) -> tuple[str, ...]:
49
    args = [*isort.args]
1✔
50
    if is_isort5 and len(isort.config) == 1:
1✔
UNCOV
51
        explicitly_configured_config_args = [
×
52
            arg
53
            for arg in isort.args
54
            if (
55
                arg.startswith("--sp")
56
                or arg.startswith("--settings-path")
57
                or arg.startswith("--settings-file")
58
                or arg.startswith("--settings")
59
            )
60
        ]
61
        # TODO: Deprecate manually setting this option, but wait until we deprecate
62
        #  `[isort].config` to be a string rather than list[str] option.
UNCOV
63
        if not explicitly_configured_config_args:
×
UNCOV
64
            args.append(f"--settings={isort.config[0]}")
×
65
    args.extend(source_files)
1✔
66
    return tuple(args)
1✔
67

68

69
@rule(desc="Format with isort", level=LogLevel.DEBUG)
1✔
70
async def isort_fmt(
1✔
71
    request: IsortRequest.Batch, isort: Isort, keep_sandboxes: KeepSandboxes
72
) -> FmtResult:
73
    isort_pex_get = create_venv_pex(**implicitly(isort.to_pex_request()))
1✔
74
    config_files_get = find_config_file(isort.config_request(request.snapshot.dirs))
1✔
75
    isort_pex, config_files = await concurrently(isort_pex_get, config_files_get)
1✔
76

77
    # Isort 5+ changes how config files are handled. Determine which semantics we should use.
78
    is_isort5 = False
1✔
79
    if isort.config:
1✔
UNCOV
80
        isort_pex_info = await determine_venv_pex_resolve_info(isort_pex)
×
UNCOV
81
        isort_info = isort_pex_info.find("isort")
×
UNCOV
82
        is_isort5 = isort_info is not None and isort_info.version.major >= 5
×
83

84
    input_digest = await merge_digests(
1✔
85
        MergeDigests((request.snapshot.digest, config_files.snapshot.digest))
86
    )
87
    description = f"Run isort on {pluralize(len(request.files), 'file')}."
1✔
88
    result = await execute_process_or_raise(
1✔
89
        **implicitly(
90
            VenvPexProcess(
91
                isort_pex,
92
                argv=generate_argv(request.files, isort, is_isort5=is_isort5),
93
                input_digest=input_digest,
94
                output_files=request.files,
95
                description=description,
96
                level=LogLevel.DEBUG,
97
            )
98
        )
99
    )
100

101
    if b"Failed to pull configuration information" in result.stderr:
1✔
UNCOV
102
        raise ProcessExecutionFailure(
×
103
            -1,
104
            result.stdout,
105
            result.stderr,
106
            description,
107
            keep_sandboxes=keep_sandboxes,
108
        )
109

110
    return await FmtResult.create(request, result)
1✔
111

112

113
def rules():
1✔
114
    return (
1✔
115
        *collect_rules(),
116
        *IsortRequest.rules(),
117
        *pex.rules(),
118
    )
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