• 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

44.26
/src/python/pants/help/help_tools.py
1
# Copyright 2021 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 collections.abc import Generator, Iterable
1✔
6
from dataclasses import dataclass
1✔
7
from functools import partial
1✔
8
from itertools import chain
1✔
9
from textwrap import wrap
1✔
10
from typing import cast
1✔
11

12
from pants.help.help_info_extracter import AllHelpInfo, OptionScopeHelpInfo
1✔
13
from pants.help.maybe_color import MaybeColor
1✔
14
from pants.util.docutil import terminal_width
1✔
15

16

17
@dataclass(frozen=True)
1✔
18
class ToolHelpInfo:
1✔
19
    name: str
1✔
20
    description: str
1✔
21
    version: str
1✔
22
    url_template: str | None
1✔
23

24
    @classmethod
1✔
25
    def from_option_scope_help_info(cls, oshi: OptionScopeHelpInfo) -> ToolHelpInfo | None:
1✔
UNCOV
26
        version, url_template = cls._get_tool_info(oshi)
×
UNCOV
27
        if not version:
×
UNCOV
28
            return None
×
UNCOV
29
        return cls(
×
30
            name=oshi.scope,
31
            description=oshi.description,
32
            version=version,
33
            url_template=url_template,
34
        )
35

36
    @classmethod
1✔
37
    def iter(cls, all_help_info: AllHelpInfo) -> Generator[ToolHelpInfo, None, None]:
1✔
38
        for oshi in all_help_info.non_deprecated_option_scope_help_infos():
×
39
            tool_info = cls.from_option_scope_help_info(oshi)
×
40
            if tool_info:
×
41
                yield tool_info
×
42

43
    @staticmethod
1✔
44
    def print_all(tool_help_infos: Iterable[ToolHelpInfo], color: MaybeColor) -> None:
1✔
45
        this = tuple(tool_help_infos)
×
46
        longest_name = max(len(tool.name) for tool in this)
×
47
        width = terminal_width()
×
48

49
        for tool in this:
×
50
            tool.print(color, description_padding=longest_name + 2, width=width)
×
51

52
    def print(self, color: MaybeColor, description_padding: int, width: int) -> None:
1✔
UNCOV
53
        _wrap = partial(wrap, width=width)
×
UNCOV
54
        _max_padding = partial(
×
55
            min, int(width / 4)
56
        )  # Do not use more than 25% of the width on padding.
57

UNCOV
58
        def _indent(indent: int) -> str:
×
UNCOV
59
            return " " * cast(int, _max_padding(indent))
×
60

UNCOV
61
        lines = _wrap(
×
62
            f"{self.name.ljust(description_padding)}{self.description}",
63
            subsequent_indent=_indent(description_padding),
64
        )
UNCOV
65
        lines[0] = lines[0].replace(self.name, color.maybe_cyan(self.name), 1)
×
UNCOV
66
        version = _wrap(
×
67
            f"Version: {self.version}",
68
            initial_indent=_indent(description_padding),
69
            subsequent_indent=_indent(description_padding),
70
        )
UNCOV
71
        if not self.url_template:
×
72
            url_template = []
×
73
        else:
UNCOV
74
            url_template = _wrap(
×
75
                f"URL template: {self.url_template}",
76
                initial_indent=_indent(description_padding),
77
                subsequent_indent=_indent(description_padding),
78
            )
UNCOV
79
        print("\n".join(lines))
×
UNCOV
80
        print(color.maybe_magenta("\n".join([*version, *url_template, ""])))
×
81

82
    @classmethod
1✔
83
    def _get_tool_info(cls, oshi: OptionScopeHelpInfo) -> tuple[str | None, str | None]:
1✔
UNCOV
84
        return (
×
85
            cls._get_option_value(oshi, "version"),
86
            cls._get_option_value(oshi, "url_template"),
87
        )
88

89
    @staticmethod
1✔
90
    def _get_option_value(oshi: OptionScopeHelpInfo, config_key: str) -> str | None:
1✔
UNCOV
91
        for ohi in chain(oshi.basic, oshi.advanced):
×
UNCOV
92
            if ohi.config_key == config_key and ohi.typ is str:
×
UNCOV
93
                rank = ohi.value_history and ohi.value_history.final_value
×
UNCOV
94
                if rank:
×
UNCOV
95
                    info = f" ({rank.details})" if rank.details else ""
×
UNCOV
96
                    return f"{rank.value}{info}"
×
97
                return cast(str, ohi.default)
×
UNCOV
98
        return None
×
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