gh-111474: Add color and a fancy output mode to regrtest#111475
gh-111474: Add color and a fancy output mode to regrtest#111475Yhg1s wants to merge 10 commits intopython:mainfrom
Conversation
|
(Making the PR a draft one because I have yet to add tests for the new code.) |
|
Just curious - what does the output look like if the background is white-ish? I would assume that's a very common scenario. |
|
It depends on the terminal's colors. I don't have a dark-on-light terminal configuration handy myself (I only ever use light-on-dark), but I would generally expect such configurations to have reasonable contrasting colors for green, yellow and red. (I could make the colors configurable, but I'd still want to stick to the basic 16 vt100 colors because of their ubiquity.) |
|
On Windows, new -h output is The progress_reporter set should be indented 2 more spaces. argparse bug? I tried running on Windows since I believe CommandPrompt and/or PowerShell either do or can be |
sobolevn
left a comment
There was a problem hiding this comment.
Just looking at annotations right now :)
The feature itself looks great! Thank you!
| self.color = False | ||
| self.load_threshold = os.process_cpu_count() | ||
|
|
||
| def error(self, s) -> str: |
There was a problem hiding this comment.
| def error(self, s) -> str: | |
| def error(self, s: str) -> str: |
| return s | ||
| return f'{self.ERROR_COLOR}{s}{self.RESET_COLOR}' | ||
|
|
||
| def warning(self, s) -> str: |
There was a problem hiding this comment.
| def warning(self, s) -> str: | |
| def warning(self, s: str) -> str: |
| return f'{self.INFO_COLOR}{s}{self.RESET_COLOR}' | ||
|
|
||
| def log(self, line: str = '') -> None: | ||
| def good(self, s) -> str: |
There was a problem hiding this comment.
| def good(self, s) -> str: | |
| def good(self, s: str) -> str: |
| return s | ||
| return f'{self.GOOD_COLOR}{s}{self.RESET_COLOR}' | ||
|
|
||
| def load_color(self, load_avg: float): |
There was a problem hiding this comment.
| def load_color(self, load_avg: float): | |
| def load_color(self, load_avg: float) -> str: |
| load = self.error(load) | ||
| return load | ||
|
|
||
| def state_color(self, text: str, state: str | None): |
There was a problem hiding this comment.
| def state_color(self, text: str, state: str | None): | |
| def state_color(self, text: str, state: State | str | None) -> str: |
| if self._quiet: | ||
| return | ||
| def display_progress(self, test_index: int, text: str, | ||
| stdout: str|None = None) -> None: |
There was a problem hiding this comment.
nit
| stdout: str|None = None) -> None: | |
| stdout: str | None = None) -> None: |
| class StatusRemovingWrapper(io.TextIOWrapper): | ||
| # Set status_size here to avoid having to override __init__. | ||
| status_size = 0 | ||
| def write(self, msg): |
There was a problem hiding this comment.
| def write(self, msg): | |
| def write(self, msg: str) -> None: |
| super().write(msg) | ||
|
|
||
|
|
||
| def replace_stdout(): |
There was a problem hiding this comment.
| def replace_stdout(): | |
| def replace_stdout() -> None: |
| run_workers.PROGRESS_UPDATE = 5 | ||
| super().__init__(results, ns) | ||
|
|
||
| def setup_terminal(self): |
There was a problem hiding this comment.
| def setup_terminal(self): | |
| def setup_terminal(self) -> None: |
| sys.stdout.status_size = report.count('\n') + 1 # type: ignore[attr-defined] | ||
|
|
||
|
|
||
| def detect_vt100_capability(): |
There was a problem hiding this comment.
| def detect_vt100_capability(): | |
| def detect_vt100_capability() -> bool: |
|
One way to implement a tkinter alternative in a followup issue/PR would be to add a 'tkgui' (or whatever) option to the reporter options. If selected, it could initialize a GuiLogger subclass of FancyLogger with a different setup_terminal() that would initialize a TestOutput window and do a different stdout replacement. Then the VT100 commands could be removed (with REs) in that replacement and replaced with terminal actions. I believe logic in the replacement write() function could replace the status removal stuff. |
Something to consider: many tools accept a three-state option for And pre-commit: Following https://no-color.org/, these options override |
…in the logger class. Add a new (optional) logger class that uses VT100 escape sequences for colourised, multi-line status reports.
…e to print skips on a line of their own even if they would fit in a regular status report.
…to just the fancy reporter.
long-running tests finish.
673c3dd to
6941b25
Compare
|
This PR is stale because it has been open for 30 days with no activity. |
Refactor regrtest to push more decisions about formatting to the
Loggerclass. Add color support toLogger, and add aFancyLoggersubclass that uses vt100 terminal control to make the test output much more condensed and easier to visually scan.The color support for logger uses just bold green, bold red and normal yellow to print "good", "bad" and "notable" things. This makes anomalous things and interleaved test output stand out a lot more:
Color support is enabled by passing
--colorto regrtest (for example by setting the EXTRATESTOPTS environment variable in themake testcall.) It doesn't try to detect color support. It obeys theNO_COLORenvironment variable to disable color.The fancy logger is enabled by passing
--progress_reporter=fancy(or by passing--progress_reporter=detectand having a functioning terminal with a known terminal type). It enables color by default, but it still obeysNO_COLOR. The fancy logger will keep redrawing the same lines on the screen rather than printing new lines, reporting all running tests. Test output, test failures, and output that is longer than can be printed on a single line will still appear on their own lines, without being overwritten. (The exception is still-running tests; if those are too long they will get truncated as long as they are running, but are printed in full when they finish.) An additional option,--fancy_report_skip_reason, can be passed to make the fancy reporter print test skips with full test reason on a line of their own.Here is a short demo of the fancy reporter running:
fancy-regrtest-short-demo.mp4
Here's what it looks like when test output needs to be printed:
And here's what it looks like when using the
--fancy_report_skip_reasonoption is added:The refactoring to support the fancy output logger are probably enough to also enable a Tkinter-based logger, although that's more work than I'm willing to put into it (since I would not use it myself).
With a very small exception, existing behaviour is not changed. The new options (
--colorand--progress_reporter) have to explicitly be passed, via theEXTRATESTOPTSenvironment variable or theTESTOPTSmake variable, to enable them. The exception is the regrtest output when it's been waiting on running tests and doesn't have any test results to report for more than 30 seconds. Before the refactoring this looked like:but now it looks like:
Changing the output back is not impossible, but to my eyes the new output makes more sense anyway.