Skip to content

Commit bf3a3b7

Browse files
FindHaometa-codesync[bot]
authored andcommitted
Make rich a default dependency (#366)
Summary: Pull Request resolved: #366 rich is already available in Meta's internal third-party (fbsource//third-party/pypi/rich:rich, v14.0.0) and is a widely used package. Making it a default dependency ensures the bisect TUI works out of the box without requiring users to manually install it. Changes: - Add rich to BUCK deps for tritonparse_lib - Add rich>=13.0 to pyproject.toml dependencies for OSS Reviewed By: xuzhao9 Differential Revision: D98795336 fbshipit-source-id: fd5cc917e8a36a128cdf9fab98298309a430a617
1 parent 7dcb006 commit bf3a3b7

4 files changed

Lines changed: 19 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "tritonparse"
77
dynamic = ["version"]
8-
dependencies = ["orjson>=3.9"]
8+
dependencies = ["orjson>=3.9", "rich>=13.0"]
99
requires-python = ">=3.10"
1010
description = "TritonParse: A Compiler Tracer, Visualizer, and mini-Reproducer Generator for Triton Kernels"
1111
readme = "README.md"

tritonparse/bisect/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
from tritonparse.bisect.ui import (
2828
BisectProgress,
2929
BisectUI,
30-
is_rich_available,
3130
print_final_summary,
32-
RICH_AVAILABLE,
3331
SummaryMode,
3432
)
3533

@@ -46,15 +44,13 @@
4644
"CommitDetectorError",
4745
"CommitPair",
4846
"EnvironmentManager",
49-
"is_rich_available",
5047
"LLVMBisectError",
5148
"LLVMBisector",
5249
"LLVMBumpInfo",
5350
"PairTester",
5451
"PairTesterError",
5552
"PairTestResult",
5653
"print_final_summary",
57-
"RICH_AVAILABLE",
5854
"ShellExecutor",
5955
"StateManager",
6056
"SummaryMode",

tritonparse/bisect/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def _orchestrate_workflow(
621621
command_log=str(logger.command_log_path) if logger else None,
622622
elapsed_time=ui.progress.elapsed_seconds,
623623
logger=logger,
624+
use_rich=ui._rich_enabled,
624625
)
625626

626627
return 0 if state and state.phase == BisectPhase.COMPLETED else 1
@@ -838,6 +839,7 @@ def _handle_triton_bisect(args: argparse.Namespace) -> int:
838839
command_log=str(logger.command_log_path) if logger else None,
839840
elapsed_time=ui.progress.elapsed_seconds,
840841
logger=logger,
842+
use_rich=ui._rich_enabled,
841843
)
842844

843845
return 0 if culprit else 1
@@ -1006,6 +1008,7 @@ def _handle_pair_test(args: argparse.Namespace) -> int:
10061008
command_log=str(logger.command_log_path) if logger else None,
10071009
elapsed_time=ui.progress.elapsed_seconds,
10081010
logger=logger,
1011+
use_rich=ui._rich_enabled,
10091012
)
10101013

10111014
# Return success if we found a failing pair or all passed
@@ -1135,6 +1138,7 @@ def _handle_llvm_only(args: argparse.Namespace) -> int:
11351138
command_log=str(logger.command_log_path) if logger else None,
11361139
elapsed_time=ui.progress.elapsed_seconds,
11371140
logger=logger,
1141+
use_rich=ui._rich_enabled,
11381142
)
11391143

11401144
return 0 if culprit else 1

tritonparse/bisect/ui.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Rich TUI interface for bisect operations.
55
66
This module provides a split-screen terminal UI for displaying bisect progress
7-
and real-time command output. It gracefully falls back to plain text when
8-
Rich is not available or when running in non-TTY environments.
7+
and real-time command output. It falls back to plain text when running in
8+
non-TTY environments or when Rich TUI is disabled via --no-tui.
99
"""
1010

1111
import re
@@ -18,17 +18,11 @@
1818
if TYPE_CHECKING:
1919
from tritonparse.bisect.logger import BisectLogger
2020

21-
# Graceful fallback if rich not installed
22-
try:
23-
from rich.console import Console
24-
from rich.layout import Layout
25-
from rich.live import Live
26-
from rich.panel import Panel
27-
from rich.text import Text
28-
29-
RICH_AVAILABLE = True
30-
except ImportError:
31-
RICH_AVAILABLE = False
21+
from rich.console import Console
22+
from rich.layout import Layout
23+
from rich.live import Live
24+
from rich.panel import Panel
25+
from rich.text import Text
3226

3327
# GitHub commit URL mapping - for generating clickable links
3428
GITHUB_COMMIT_URLS = {
@@ -178,9 +172,6 @@ def __init__(self, enabled: bool = True) -> None:
178172
if not enabled:
179173
self._rich_enabled = False
180174
self._disabled_reason = "disabled by --no-tui flag"
181-
elif not RICH_AVAILABLE:
182-
self._rich_enabled = False
183-
self._disabled_reason = "rich library not installed (pip install rich)"
184175
elif not sys.stdout.isatty() or not sys.stderr.isatty():
185176
self._rich_enabled = False
186177
self._disabled_reason = "not running in a TTY (e.g., piped output or CI)"
@@ -576,11 +567,6 @@ def _parse_and_update_progress(self, line: str) -> None:
576567
self.update_progress(steps_remaining=steps_remaining)
577568

578569

579-
def is_rich_available() -> bool:
580-
"""Check if Rich library is available."""
581-
return RICH_AVAILABLE
582-
583-
584570
def _generate_title(mode: SummaryMode, success: bool = True) -> str:
585571
"""
586572
Generate panel title based on mode.
@@ -618,6 +604,7 @@ def _print_pair_test_summary(
618604
command_log: Optional[str],
619605
elapsed_time: Optional[float],
620606
logger: Optional["BisectLogger"],
607+
use_rich: bool = True,
621608
) -> None:
622609
"""
623610
Print pair test summary with Rich formatting (or plain text fallback).
@@ -630,8 +617,9 @@ def _print_pair_test_summary(
630617
command_log: Command log file path.
631618
elapsed_time: Total execution time in seconds.
632619
logger: Optional BisectLogger to write summary to log file.
620+
use_rich: Whether to use Rich formatting. If False, uses plain text.
633621
"""
634-
if RICH_AVAILABLE:
622+
if use_rich:
635623
console = Console(record=True)
636624
_print_pair_test_summary_rich(
637625
result, error_msg, log_dir, log_file, command_log, elapsed_time, console
@@ -853,6 +841,7 @@ def print_final_summary(
853841
command_log: Optional[str] = None,
854842
elapsed_time: Optional[float] = None,
855843
logger: Optional["BisectLogger"] = None,
844+
use_rich: bool = True,
856845
) -> None:
857846
"""
858847
Print final bisect summary with Rich formatting (or plain text fallback).
@@ -870,6 +859,7 @@ def print_final_summary(
870859
command_log: Command log file path (shown on error).
871860
elapsed_time: Total execution time in seconds.
872861
logger: Optional BisectLogger to write summary to log file.
862+
use_rich: Whether to use Rich formatting. If False, uses plain text.
873863
"""
874864
# Handle pair test mode separately
875865
if mode == SummaryMode.PAIR_TEST:
@@ -881,6 +871,7 @@ def print_final_summary(
881871
command_log,
882872
elapsed_time,
883873
logger,
874+
use_rich=use_rich,
884875
)
885876
return
886877

@@ -897,7 +888,7 @@ def print_final_summary(
897888
and llvm_bump_info.is_llvm_bump
898889
)
899890

900-
if RICH_AVAILABLE:
891+
if use_rich:
901892
# Use record=True to capture output for logging
902893
console = Console(record=True)
903894
_print_final_summary_rich(

0 commit comments

Comments
 (0)