Skip to content

Commit ba6d59f

Browse files
committed
add null_progress function
1 parent 818a10f commit ba6d59f

5 files changed

Lines changed: 16 additions & 5 deletions

File tree

docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Creating Progress Bars
1111

1212
.. autofunction:: make_progress
1313

14+
.. autofunction:: null_progress
15+
1416
Progress Bar Interface
1517
----------------------
1618

progress_api/api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Progress(ABC):
2525
"""
2626

2727
name: str
28-
spec: backends.ProgressBarSpec
2928

3029
@abstractmethod
3130
def set_label(self, label: Optional[str]) -> None:
@@ -147,3 +146,14 @@ def make_progress(
147146

148147
spec = backends.ProgressBarSpec(logger, label, total, unit, sl, leave)
149148
return config.get_backend().create_bar(spec)
149+
150+
151+
def null_progress() -> Progress:
152+
"""
153+
Create a null progress bar, regardless of the configured backend. This is
154+
useful to allow progress reporting to be optional without littering code
155+
with conditionals.
156+
"""
157+
from progress_api.backends.null import NullProgress
158+
159+
return NullProgress()

progress_api/backends/enlighten.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class EnlightenProgressBackend(ProgressBackend):
5151
Progress bar backend that doesn't emit any progress.
5252
"""
5353

54+
spec: ProgressBarSpec
5455
manager: Manager
5556
state_colors: dict[str, str]
5657

progress_api/backends/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def create_bar(self, spec: ProgressBarSpec) -> api.Progress:
3232

3333

3434
class MockProgress(api.Progress):
35+
spec: ProgressBarSpec
3536
backend: MockProgressBackend
3637

3738
def __init__(self, backend: MockProgressBackend, spec: ProgressBarSpec):

progress_api/backends/null.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ class NullProgressBackend(ProgressBackend):
2121
"""
2222

2323
def create_bar(self, spec: ProgressBarSpec) -> api.Progress:
24-
return NullProgress(spec)
24+
return NullProgress()
2525

2626

2727
class NullProgress(api.Progress):
28-
def __init__(self, spec: ProgressBarSpec):
29-
self.spec = spec
30-
3128
def set_label(self, label: Optional[str]):
3229
pass
3330

0 commit comments

Comments
 (0)