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

pantsbuild / pants / 22360764254

24 Feb 2026 04:46PM UTC coverage: 88.798% (-4.1%) from 92.935%
22360764254

Pull #23133

github

web-flow
Merge 4c056364c into 4d038bd74
Pull Request #23133: Add buildctl engine

181 of 264 new or added lines in 8 files covered. (68.56%)

3184 existing lines in 145 files now uncovered.

77555 of 87339 relevant lines covered (88.8%)

3.34 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
9✔
4

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

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

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

14

15
class Console(SideEffecting):
9✔
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__(
9✔
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
9✔
31
        self._stdout = stdout or sys.stdout
9✔
32
        self._stderr = stderr or sys.stderr
9✔
33
        self._use_colors = use_colors
9✔
34
        self._session = session
9✔
35
        self._enforce_effects = self._session is not None
9✔
36

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

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

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

58
    def input(self, prompt: str | None = None) -> str:
9✔
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:
9✔
65
        self.stdout.write(payload)
6✔
66

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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