fix: use global rich.Console object
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from . import logs
|
||||
|
||||
_console, _logs_listener = logs.configure()
|
||||
_logs_listener = logs.configure()
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
@@ -11,6 +11,7 @@ import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import aiofiles
|
||||
import rich
|
||||
from aiohttp import ClientSession, TCPConnector
|
||||
from rich.progress import BarColumn, MofNCompleteColumn, Progress, TextColumn
|
||||
from rich.table import Table
|
||||
@@ -113,7 +114,6 @@ async def main() -> None:
|
||||
TextColumn("[green]{task.fields[col2]}"),
|
||||
BarColumn(),
|
||||
MofNCompleteColumn(),
|
||||
console=_console,
|
||||
transient=True,
|
||||
) as progress:
|
||||
scrape = scraper.scrape_all(
|
||||
@@ -147,7 +147,7 @@ async def main() -> None:
|
||||
if settings.check_website:
|
||||
storage.remove_unchecked()
|
||||
count_after_checking = storage.get_count()
|
||||
_console.print(
|
||||
rich.print(
|
||||
get_summary_table(
|
||||
before=count_before_checking, after=count_after_checking
|
||||
)
|
||||
|
||||
@@ -8,25 +8,20 @@ from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
|
||||
def configure() -> tuple[Console, logging.handlers.QueueListener]:
|
||||
def configure() -> logging.handlers.QueueListener:
|
||||
log_queue: queue.Queue[Any] = queue.Queue()
|
||||
|
||||
logging.root.setLevel(logging.INFO)
|
||||
logging.root.addHandler(logging.handlers.QueueHandler(log_queue))
|
||||
|
||||
# Start logging before importing rich for the first time
|
||||
from rich.console import Console # noqa: PLC0415
|
||||
from rich.logging import RichHandler # noqa: PLC0415
|
||||
|
||||
console = Console()
|
||||
stream_handler = RichHandler(
|
||||
console=console,
|
||||
omit_repeated_times=False,
|
||||
show_path=False,
|
||||
log_time_format=logging.Formatter.default_time_format,
|
||||
)
|
||||
|
||||
return console, logging.handlers.QueueListener(log_queue, stream_handler)
|
||||
return logging.handlers.QueueListener(log_queue, stream_handler)
|
||||
|
||||
Reference in New Issue
Block a user