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

pantsbuild / pants / 24145945949

08 Apr 2026 04:14PM UTC coverage: 82.077% (-10.8%) from 92.91%
24145945949

Pull #23233

github

web-flow
Merge 089d98e3c into 9036734c9
Pull Request #23233: Introduce a LockfileFormat enum.

8 of 11 new or added lines in 4 files covered. (72.73%)

7635 existing lines in 306 files now uncovered.

63732 of 77649 relevant lines covered (82.08%)

2.96 hits per line

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

93.15
/src/python/pants/engine/console.py
1
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
7✔
4

5
import sys
7✔
6
from collections.abc import Callable
7✔
7
from typing import TextIO
7✔
8

9
from colors import blue, cyan, green, magenta, red, yellow
7✔
10

11
from pants.engine.engine_aware import SideEffecting
7✔
12
from pants.engine.internals.scheduler import SchedulerSession
7✔
13

14

15
class Console(SideEffecting):
7✔
16
    """Class responsible for writing text to the console while Pants is running.
17

18
    A SchedulerSession should always be set in production usage, in order to track side effects, and
19
    tear down any running UI before stdio is rendered.
20
    """
21

22
    def __init__(
7✔
23
        self,
24
        stdin: TextIO | None = None,
25
        stdout: TextIO | None = None,
26
        stderr: TextIO | None = None,
27
        use_colors: bool = True,
28
        session: SchedulerSession | None = None,
29
    ):
30
        self._stdin = stdin or sys.stdin
7✔
31
        self._stdout = stdout or sys.stdout
7✔
32
        self._stderr = stderr or sys.stderr
7✔
33
        self._use_colors = use_colors
7✔
34
        self._session = session
7✔
35
        self._enforce_effects = self._session is not None
7✔
36

37
    @property
7✔
38
    def stdin(self) -> TextIO:
7✔
39
        if self._session:
1✔
40
            self.side_effected()
×
41
            self._session.teardown_dynamic_ui()
×
42
        return self._stdin
1✔
43

44
    @property
7✔
45
    def stdout(self) -> TextIO:
7✔
46
        if self._session:
7✔
47
            self.side_effected()
6✔
48
            self._session.teardown_dynamic_ui()
6✔
49
        return self._stdout
7✔
50

51
    @property
7✔
52
    def stderr(self) -> TextIO:
7✔
53
        if self._session:
3✔
54
            self.side_effected()
3✔
55
            self._session.teardown_dynamic_ui()
3✔
56
        return self._stderr
3✔
57

58
    def input(self, prompt: str | None = None) -> str:
7✔
59
        """Equivalent to the `input` builtin, but clears any running UI before rendering."""
60
        if prompt is not None:
1✔
61
            self.write_stdout(prompt)
1✔
62
        return self.stdin.readline().rstrip("\n")
1✔
63

64
    def write_stdout(self, payload: str) -> None:
7✔
65
        self.stdout.write(payload)
5✔
66

67
    def write_stderr(self, payload: str) -> None:
7✔
68
        self.stderr.write(payload)
3✔
69

70
    def print_stdout(self, payload: str, end: str = "\n") -> None:
7✔
71
        self.write_stdout(f"{payload}{end}")
4✔
72

73
    def print_stderr(self, payload: str, end: str = "\n") -> None:
7✔
74
        self.write_stderr(f"{payload}{end}")
3✔
75

76
    def flush(self) -> None:
7✔
77
        self._stdout.flush()
7✔
78
        self._stderr.flush()
7✔
79

80
    def sigil_succeeded(self) -> str:
7✔
81
        """Sigil for a successful item."""
82
        return self.green("✓")
2✔
83

84
    def sigil_succeeded_with_edits(self) -> str:
7✔
85
        """Sigil for a successful item which caused an edit to the workspace."""
86
        return self.yellow("+")
1✔
87

88
    def sigil_failed(self) -> str:
7✔
89
        """Sigil for a failed item."""
90
        return self.red("✕")
1✔
91

92
    def sigil_skipped(self) -> str:
7✔
93
        """Sigil for a skipped item."""
94
        return self.yellow("-")
1✔
95

96
    @property
7✔
97
    def use_colors(self):
7✔
98
        return self._use_colors
×
99

100
    def _safe_color(self, text: str, color: Callable[[str], str]) -> str:
7✔
101
        """We should only output color when the global flag --colors is enabled."""
102
        return color(text) if self._use_colors else text
3✔
103

104
    def blue(self, text: str) -> str:
7✔
105
        return self._safe_color(text, blue)
1✔
106

107
    def cyan(self, text: str) -> str:
7✔
UNCOV
108
        return self._safe_color(text, cyan)
×
109

110
    def green(self, text: str) -> str:
7✔
111
        return self._safe_color(text, green)
2✔
112

113
    def magenta(self, text: str) -> str:
7✔
114
        return self._safe_color(text, magenta)
×
115

116
    def red(self, text: str) -> str:
7✔
117
        return self._safe_color(text, red)
1✔
118

119
    def yellow(self, text: str) -> str:
7✔
120
        return self._safe_color(text, yellow)
2✔
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