Skip to content

Commit

Permalink
add null_progress function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed May 12, 2024
1 parent 818a10f commit ba6d59f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Creating Progress Bars

.. autofunction:: make_progress

.. autofunction:: null_progress

Progress Bar Interface
----------------------

Expand Down
12 changes: 11 additions & 1 deletion progress_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Progress(ABC):
"""

name: str
spec: backends.ProgressBarSpec

@abstractmethod
def set_label(self, label: Optional[str]) -> None:
Expand Down Expand Up @@ -147,3 +146,14 @@ def make_progress(

spec = backends.ProgressBarSpec(logger, label, total, unit, sl, leave)
return config.get_backend().create_bar(spec)


def null_progress() -> Progress:
"""
Create a null progress bar, regardless of the configured backend. This is
useful to allow progress reporting to be optional without littering code
with conditionals.
"""
from progress_api.backends.null import NullProgress

return NullProgress()
1 change: 1 addition & 0 deletions progress_api/backends/enlighten.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class EnlightenProgressBackend(ProgressBackend):
Progress bar backend that doesn't emit any progress.
"""

spec: ProgressBarSpec
manager: Manager
state_colors: dict[str, str]

Expand Down
1 change: 1 addition & 0 deletions progress_api/backends/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def create_bar(self, spec: ProgressBarSpec) -> api.Progress:


class MockProgress(api.Progress):
spec: ProgressBarSpec
backend: MockProgressBackend

def __init__(self, backend: MockProgressBackend, spec: ProgressBarSpec):
Expand Down
5 changes: 1 addition & 4 deletions progress_api/backends/null.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ class NullProgressBackend(ProgressBackend):
"""

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


class NullProgress(api.Progress):
def __init__(self, spec: ProgressBarSpec):
self.spec = spec

def set_label(self, label: Optional[str]):
pass

Expand Down

0 comments on commit ba6d59f

Please sign in to comment.