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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

57.53
/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
3✔
4

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

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

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

14

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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