Coverage for src/bioimageio/spec/_internal/progress.py: 100%
26 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-18 09:17 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-18 09:17 +0000
1from __future__ import annotations
3from abc import abstractmethod
4from typing import Any, Protocol
6from rich.progress import Progress
9class ProgressbarLike(Protocol):
10 """Progressbar protocol modeled after tqdm"""
12 total: int | None
14 @abstractmethod
15 def update(self, increment: int, /) -> Any: ...
17 @abstractmethod
18 def reset(self): ...
20 @abstractmethod
21 def close(self): ...
23 @abstractmethod
24 def set_description(self, description: str, /, refresh: bool = True): ...
27class RichTaskBar(ProgressbarLike):
28 def __init__(self, description: str, *, parent: Progress, total: int | None):
29 super().__init__()
30 self.task_id = parent.add_task(description, total=total)
31 self.parent = parent
32 self.total = total
34 def update(self, increment: int, /):
35 self.parent.advance(self.task_id, increment)
37 def reset(self):
38 self.parent.reset(self.task_id)
40 def close(self):
41 self.parent.remove_task(self.task_id)
43 def set_description(self, description: str, /, refresh: bool = True):
44 self.parent.update(self.task_id, description=description, refresh=refresh)
47class RichOverallProgress:
48 def __init__(self):
49 super().__init__()
50 self.progress = Progress()
52 def __call__(self, description: str = "", *, total: int | None = None):
53 return RichTaskBar(description, parent=self.progress, total=total)