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

pantsbuild / pants / 20328535594

18 Dec 2025 06:46AM UTC coverage: 57.969% (-22.3%) from 80.295%
20328535594

Pull #22954

github

web-flow
Merge ccc9c5409 into 407284c67
Pull Request #22954: free up disk space in runner image

39083 of 67421 relevant lines covered (57.97%)

0.91 hits per line

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

0.0
/src/python/pants/backend/python/lint/isort/subsystem.py
1
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
×
5

6
import os.path
×
7
from collections.abc import Iterable
×
8

9
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
×
10
from pants.backend.python.target_types import ConsoleScript
×
11
from pants.core.goals.resolves import ExportableTool
×
12
from pants.core.util_rules.config_files import ConfigFilesRequest
×
13
from pants.engine.rules import collect_rules
×
14
from pants.engine.unions import UnionRule
×
15
from pants.option.option_types import ArgsListOption, BoolOption, FileListOption, SkipOption
×
16
from pants.util.strutil import softwrap
×
17

18

19
class Isort(PythonToolBase):
×
20
    options_scope = "isort"
×
21
    name = "isort"
×
22
    help_short = "The Python import sorter tool (https://pycqa.github.io/isort/)."
×
23

24
    default_main = ConsoleScript("isort")
×
25
    default_requirements = ["isort[pyproject,colors]>=5.9.3,<6.0"]
×
26

27
    register_interpreter_constraints = True
×
28

29
    default_lockfile_resource = ("pants.backend.python.lint.isort", "isort.lock")
×
30

31
    skip = SkipOption("fmt", "lint")
×
32
    args = ArgsListOption(example="--case-sensitive --trailing-comma")
×
33
    config = FileListOption(
×
34
        # TODO: Figure out how to deprecate this being a list in favor of a single string.
35
        #  Thanks to config autodiscovery, this option should only be used because you want
36
        #  Pants to explicitly set `--settings`, which only works w/ 1 config file.
37
        #  isort 4 users should instead use autodiscovery to support multiple config files.
38
        #  Deprecating this could be tricky, but should be possible thanks to the implicit
39
        #  add syntax.
40
        #
41
        #  When deprecating, also deprecate the user manually setting `--settings` with
42
        #  `[isort].args`.
43
        advanced=True,
44
        help=lambda cls: softwrap(
45
            f"""
46
            Path to config file understood by isort
47
            (https://pycqa.github.io/isort/docs/configuration/config_files/).
48

49
            Setting this option will disable `[{cls.options_scope}].config_discovery`. Use
50
            this option if the config is located in a non-standard location.
51

52
            If using isort 5+ and you specify only 1 config file, Pants will configure
53
            isort's argv to point to your config file.
54
            """
55
        ),
56
    )
57
    config_discovery = BoolOption(
×
58
        default=True,
59
        advanced=True,
60
        help=lambda cls: softwrap(
61
            f"""
62
            If true, Pants will include any relevant config files during
63
            runs (`.isort.cfg`, `pyproject.toml`, `setup.cfg`, `tox.ini` and `.editorconfig`).
64

65
            Use `[{cls.options_scope}].config` instead if your config is in a
66
            non-standard location.
67
            """
68
        ),
69
    )
70

71
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
×
72
        # Refer to https://pycqa.github.io/isort/docs/configuration/config_files/.
73
        check_existence = []
×
74
        check_content = {}
×
75
        for d in ("", *dirs):
×
76
            check_existence.append(os.path.join(d, ".isort.cfg"))
×
77
            check_content.update(
×
78
                {
79
                    os.path.join(d, "pyproject.toml"): b"[tool.isort]",
80
                    os.path.join(d, "setup.cfg"): b"[isort]",
81
                    os.path.join(d, "tox.ini"): b"[isort]",
82
                    os.path.join(d, ".editorconfig"): b"[*.py]",
83
                }
84
            )
85

86
        return ConfigFilesRequest(
×
87
            specified=self.config,
88
            specified_option_name=f"[{self.options_scope}].config",
89
            discovery=self.config_discovery,
90
            check_existence=check_existence,
91
            check_content=check_content,
92
        )
93

94

95
def rules():
×
96
    return [
×
97
        *collect_rules(),
98
        UnionRule(ExportableTool, Isort),
99
    ]
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