Skip to content

Commit cfc7720

Browse files
committed
refactor: add global stdout rich console
1 parent e91e56e commit cfc7720

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

bowtie/_cli.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def __getattr__(self, attr: str) -> int:
8888

8989
EX = _EX()
9090

91+
STDOUT = console.Console()
9192
STDERR = console.Console(stderr=True)
9293

9394
STARTUP_ERRORS = (CannotConnect, NoSuchImplementation, StartupFailed)
@@ -676,10 +677,10 @@ def to_serializable(
676677
click.echo(json.dumps(to_serializable(results), indent=2)) # type: ignore[reportGeneralTypeIssues]
677678
case "pretty":
678679
table = to_table(report, results) # type: ignore[reportGeneralTypeIssues]
679-
console.Console().print(table)
680+
STDOUT.print(table)
680681
case "markdown":
681682
table = to_markdown_table(report, results) # type: ignore[reportGeneralTypeIssues]
682-
console.Console().print(table)
683+
STDOUT.print(table)
683684

684685
return exit_code
685686

@@ -1489,7 +1490,7 @@ def filter_benchmarks(
14891490
dialect=dialect,
14901491
)
14911492
for file in files:
1492-
console.Console().file.write(f"{file}\n")
1493+
STDOUT.file.write(f"{file}\n")
14931494

14941495

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

17371737
async for _, each in start():
17381738
metadata = [(k, v) for k, v in each.info.serializable().items() if v]
@@ -1756,7 +1756,7 @@ async def info(
17561756
serializable[each.id] = dict(metadata)
17571757
case "pretty":
17581758
table = _info_table_for(dict(metadata))
1759-
out.print(table, "\n")
1759+
STDOUT.print(table, "\n")
17601760
case "markdown":
17611761
click.echo(
17621762
"\n".join(
@@ -1785,7 +1785,7 @@ async def download_versions_of(id: ConnectableId) -> frozenset[str]:
17851785
DownloadColumn(),
17861786
"•",
17871787
TimeElapsedColumn(),
1788-
console=console.Console(),
1788+
console=STDOUT,
17891789
transient=True,
17901790
)
17911791
task = progress.add_task(
@@ -1845,7 +1845,7 @@ async def download_and_parse_reports_for(
18451845
MofNCompleteColumn(),
18461846
"•",
18471847
TimeElapsedColumn(),
1848-
console=console.Console(),
1848+
console=STDOUT,
18491849
transient=True,
18501850
)
18511851

@@ -2161,7 +2161,7 @@ def convert( # type: ignore[reportIncompatibleMethodOverride]
21612161
MofNCompleteColumn(),
21622162
"•",
21632163
TimeElapsedColumn(),
2164-
console=console.Console(),
2164+
console=STDOUT,
21652165
transient=True,
21662166
)
21672167
dialects = (
@@ -2386,11 +2386,11 @@ async def download_versions_and_parse_reports_for(
23862386
]
23872387
click.echo(json.dumps(serializable, indent=2))
23882388
case "pretty":
2389-
console.Console().print(
2389+
STDOUT.print(
23902390
_trend_table_for(id, versions, dialects_trend),
23912391
)
23922392
case "markdown":
2393-
console.Console().print(
2393+
STDOUT.print(
23942394
_trend_table_in_markdown_for(id, versions, dialects_trend),
23952395
)
23962396

@@ -2424,11 +2424,10 @@ async def smoke(start: Starter, format: _F, echo: Callable[..., None]) -> int:
24242424
output = {id: result.serializable() for id, _, result in results}
24252425
echo(json.dumps(output, indent=2))
24262426
case [(_, _, result)], "pretty":
2427-
console.Console().print(result)
2427+
STDOUT.print(result)
24282428
case _, "pretty":
2429-
out = console.Console()
24302429
for _, _, each in results:
2431-
out.print(each)
2430+
STDOUT.print(each)
24322431
case _, "markdown":
24332432
for _, info, result in results:
24342433
echo(f"# {info.name} ({info.language})\n")

0 commit comments

Comments
 (0)