From 85d4799831220ba6b3b0fae97f084cce65017499 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Nov 2024 21:22:25 +0000 Subject: [PATCH 1/5] Mute status messages unless --verbose is used --- abi3audit/_cli.py | 3 +++ abi3audit/_state.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/abi3audit/_cli.py b/abi3audit/_cli.py index bb15125..6479603 100644 --- a/abi3audit/_cli.py +++ b/abi3audit/_cli.py @@ -227,6 +227,9 @@ def main() -> None: if args.debug: logging.root.setLevel("DEBUG") + if args.verbose: + status.initiate() + specs = [] for spec in args.specs: try: diff --git a/abi3audit/_state.py b/abi3audit/_state.py index 79be29e..725ab0d 100644 --- a/abi3audit/_state.py +++ b/abi3audit/_state.py @@ -10,6 +10,24 @@ from rich.console import Console +class Status(object): + def __init__(self, console: Console): + self._console = console + self._status = None + def __enter__(self): + if self._status: + self._status.__enter__() + return self + def __exit__(self, *args): + if self._status: + self._status.__exit__(*args) + def initiate(self): + self._status = self._console.status("[green]Processing inputs", spinner="clock") + def update(self, s: str): + if self._status: + self._status.update(s) + + # TODO: Remove this once rich's NO_COLOR handling is fixed. # See: https://github.com/Textualize/rich/issues/2549 _color_system: Literal["auto"] | None @@ -19,4 +37,4 @@ _color_system = "auto" console = Console(log_path=False, file=sys.stderr, color_system=_color_system) -status = console.status("[green]Processing inputs", spinner="clock") +status = Status(console) From 7a38c10a496ca96a3f0b629a1935a74c75c49b71 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Nov 2024 19:35:10 +0000 Subject: [PATCH 2/5] Ruff formatting --- abi3audit/_state.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/abi3audit/_state.py b/abi3audit/_state.py index 725ab0d..d0c86bc 100644 --- a/abi3audit/_state.py +++ b/abi3audit/_state.py @@ -10,19 +10,24 @@ from rich.console import Console + class Status(object): def __init__(self, console: Console): self._console = console self._status = None + def __enter__(self): if self._status: self._status.__enter__() return self + def __exit__(self, *args): if self._status: self._status.__exit__(*args) + def initiate(self): self._status = self._console.status("[green]Processing inputs", spinner="clock") + def update(self, s: str): if self._status: self._status.update(s) From 71fe6b8bbf054d90eeba4660e62b271bc8cb2ad2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Nov 2024 19:42:33 +0000 Subject: [PATCH 3/5] Remove object base class for Ruff --- abi3audit/_state.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abi3audit/_state.py b/abi3audit/_state.py index d0c86bc..134fbeb 100644 --- a/abi3audit/_state.py +++ b/abi3audit/_state.py @@ -11,7 +11,7 @@ from rich.console import Console -class Status(object): +class Status: def __init__(self, console: Console): self._console = console self._status = None From f97c38e8a018ddc2956338fc753955739831c338 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Nov 2024 21:35:56 +0000 Subject: [PATCH 4/5] Fix mypy errors --- abi3audit/_state.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/abi3audit/_state.py b/abi3audit/_state.py index 134fbeb..ab8375b 100644 --- a/abi3audit/_state.py +++ b/abi3audit/_state.py @@ -6,29 +6,38 @@ import os import sys -from typing import Literal +from typing import Any, Literal, Optional, Type +from types import TracebackType from rich.console import Console +from rich.status import Status -class Status: - def __init__(self, console: Console): +class StatusWrapper: + _status: Status | None + def __init__(self, console: Console) -> None: self._console = console self._status = None - def __enter__(self): + def __enter__(self) -> StatusWrapper: if self._status: self._status.__enter__() return self - def __exit__(self, *args): + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType], + ) -> Any: if self._status: - self._status.__exit__(*args) + return self._status.__exit__(exc_type, exc_val, exc_tb) + return False - def initiate(self): + def initiate(self) -> None: self._status = self._console.status("[green]Processing inputs", spinner="clock") - def update(self, s: str): + def update(self, s: str) -> None: if self._status: self._status.update(s) @@ -42,4 +51,4 @@ def update(self, s: str): _color_system = "auto" console = Console(log_path=False, file=sys.stderr, color_system=_color_system) -status = Status(console) +status = StatusWrapper(console) From fafadcdd16bf78156e84d54cf459f3fa91f4f7a0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Nov 2024 21:54:30 +0000 Subject: [PATCH 5/5] More linting fixes --- abi3audit/_state.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/abi3audit/_state.py b/abi3audit/_state.py index ab8375b..cf2c2bd 100644 --- a/abi3audit/_state.py +++ b/abi3audit/_state.py @@ -6,8 +6,8 @@ import os import sys -from typing import Any, Literal, Optional, Type from types import TracebackType +from typing import Any, Literal from rich.console import Console from rich.status import Status @@ -15,6 +15,7 @@ class StatusWrapper: _status: Status | None + def __init__(self, console: Console) -> None: self._console = console self._status = None @@ -26,9 +27,9 @@ def __enter__(self) -> StatusWrapper: def __exit__( self, - exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType], + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, ) -> Any: if self._status: return self._status.__exit__(exc_type, exc_val, exc_tb)