Skip to content

Commit

Permalink
Merge pull request #1883 from tthijm/refactor/global-stdout-console
Browse files Browse the repository at this point in the history
refactor: add global stdout rich console
  • Loading branch information
Julian authored Mar 10, 2025
2 parents e91e56e + cfc7720 commit 99f3135
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions bowtie/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __getattr__(self, attr: str) -> int:

EX = _EX()

STDOUT = console.Console()
STDERR = console.Console(stderr=True)

STARTUP_ERRORS = (CannotConnect, NoSuchImplementation, StartupFailed)
Expand Down Expand Up @@ -676,10 +677,10 @@ def to_serializable(
click.echo(json.dumps(to_serializable(results), indent=2)) # type: ignore[reportGeneralTypeIssues]
case "pretty":
table = to_table(report, results) # type: ignore[reportGeneralTypeIssues]
console.Console().print(table)
STDOUT.print(table)
case "markdown":
table = to_markdown_table(report, results) # type: ignore[reportGeneralTypeIssues]
console.Console().print(table)
STDOUT.print(table)

return exit_code

Expand Down Expand Up @@ -1489,7 +1490,7 @@ def filter_benchmarks(
dialect=dialect,
)
for file in files:
console.Console().file.write(f"{file}\n")
STDOUT.file.write(f"{file}\n")


LANGUAGE_ALIASES = {
Expand Down Expand Up @@ -1732,7 +1733,6 @@ async def info(
Show information about a supported implementation.
"""
serializable: dict[ConnectableId, dict[str, Any]] = {}
out = console.Console()

async for _, each in start():
metadata = [(k, v) for k, v in each.info.serializable().items() if v]
Expand All @@ -1756,7 +1756,7 @@ async def info(
serializable[each.id] = dict(metadata)
case "pretty":
table = _info_table_for(dict(metadata))
out.print(table, "\n")
STDOUT.print(table, "\n")
case "markdown":
click.echo(
"\n".join(
Expand Down Expand Up @@ -1785,7 +1785,7 @@ async def download_versions_of(id: ConnectableId) -> frozenset[str]:
DownloadColumn(),
"•",
TimeElapsedColumn(),
console=console.Console(),
console=STDOUT,
transient=True,
)
task = progress.add_task(
Expand Down Expand Up @@ -1845,7 +1845,7 @@ async def download_and_parse_reports_for(
MofNCompleteColumn(),
"•",
TimeElapsedColumn(),
console=console.Console(),
console=STDOUT,
transient=True,
)

Expand Down Expand Up @@ -2161,7 +2161,7 @@ def convert( # type: ignore[reportIncompatibleMethodOverride]
MofNCompleteColumn(),
"•",
TimeElapsedColumn(),
console=console.Console(),
console=STDOUT,
transient=True,
)
dialects = (
Expand Down Expand Up @@ -2386,11 +2386,11 @@ async def download_versions_and_parse_reports_for(
]
click.echo(json.dumps(serializable, indent=2))
case "pretty":
console.Console().print(
STDOUT.print(
_trend_table_for(id, versions, dialects_trend),
)
case "markdown":
console.Console().print(
STDOUT.print(
_trend_table_in_markdown_for(id, versions, dialects_trend),
)

Expand Down Expand Up @@ -2424,11 +2424,10 @@ async def smoke(start: Starter, format: _F, echo: Callable[..., None]) -> int:
output = {id: result.serializable() for id, _, result in results}
echo(json.dumps(output, indent=2))
case [(_, _, result)], "pretty":
console.Console().print(result)
STDOUT.print(result)
case _, "pretty":
out = console.Console()
for _, _, each in results:
out.print(each)
STDOUT.print(each)
case _, "markdown":
for _, info, result in results:
echo(f"# {info.name} ({info.language})\n")
Expand Down

0 comments on commit 99f3135

Please sign in to comment.