Skip to content

Commit

Permalink
Merge pull request #63 from alphatwirl/dev
Browse files Browse the repository at this point in the history
Remove `ProgressReportComplementer`
  • Loading branch information
TaiSakuma authored Jul 7, 2024
2 parents 3b72113 + 1d99189 commit e282fdc
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 228 deletions.
33 changes: 28 additions & 5 deletions atpbar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, iterable: Iterable[T], name: str, len_: int):
self.name = name
self.len_ = len_
self.id_ = uuid.uuid4()
self._done = 0

def __iter__(self) -> Iterator[T]:
with fetch_reporter() as reporter:
Expand All @@ -76,16 +77,31 @@ def __iter__(self) -> Iterator[T]:
with self._report_last():
for i, e in enumerate(self.iterable):
yield e
self._report_progress(i)
self._done = i + 1
self._report_progress()
else:
self.loop_complete = True

def _report_start(self) -> None:
report = Report(task_id=self.id_, name=self.name, done=0, total=self.len_)
report = Report(
task_id=self.id_,
name=self.name,
done=0,
total=self.len_,
first=True,
last=self._done == self.len_,
)
self._submit(report)

def _report_progress(self, i: int) -> None:
report = Report(task_id=self.id_, done=(i + 1))
def _report_progress(self) -> None:
report = Report(
task_id=self.id_,
name=self.name,
done=self._done,
total=self.len_,
first=self._done == 0,
last=self._done == self.len_,
)
self._submit(report)

@contextlib.contextmanager
Expand All @@ -102,7 +118,14 @@ def _report_last(self) -> Iterator[None]:
finally:
if self.loop_complete:
return
report = Report(task_id=self.id_, first=False, last=True)
report = Report(
task_id=self.id_,
name=self.name,
done=self._done,
total=self.len_,
first=False,
last=True,
)
self._submit(report)

def _submit(self, report: Report) -> None:
Expand Down
51 changes: 0 additions & 51 deletions atpbar/progress_report/complement.py

This file was deleted.

26 changes: 9 additions & 17 deletions atpbar/progress_report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@
from uuid import UUID


class Report(TypedDict, total=False):
class Report(TypedDict):
'''Progress report
Parameters
----------
task_id : immutable
task_id
The unique task ID.
done : int
done
The number of the iterations done so far
total : int
The total iterations to be done
name : str
A name of the task. It will be use as the label on the
progress bars.
total
The total iterations to be done
name
A name of the task. It will be use as the label on the progress bars.
first : bool
`True` if the first report for the task. If not given,
automatically determined from `done`; `True` if `done` is
0, `False` otherwise
`True` if the first report for the task.
last : bool
`True` if the last report for the task. If not given,
automatically determined from `done` and `total`; `True`
if `done` equals `total`, `False` otherwise
`True` if the last report for the task.
Notes:
------
TODO: Use typing.Required for Python 3.11 and above
'''

task_id: UUID
Expand Down
4 changes: 0 additions & 4 deletions atpbar/progress_report/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from atpbar.presentation import create_presentation
from atpbar.stream import StreamQueue, StreamRedirection, register_stream_queue

from .complement import ProgressReportComplementer
from .pickup import ProgressReportPickup
from .report import Report

Expand Down Expand Up @@ -53,7 +52,6 @@ def __init__(self) -> None:
self.stream_queue: StreamQueue = Queue()
self.interval = DEFAULT_INTERVAL # [second]
self.last_time = dict[UUID, float]()
self.complete_report = ProgressReportComplementer()
self.stream_redirection_enabled = True

def __repr__(self) -> str:
Expand Down Expand Up @@ -101,8 +99,6 @@ def report(self, report: Report) -> None:
'''

self.complete_report(report)

if not self._need_to_report(report):
return

Expand Down
12 changes: 6 additions & 6 deletions tests/presentation/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def test_repr(obj: MockProgressBar) -> None:
def test_present(obj: Presentation) -> None:
i = uuid.uuid4()
j = uuid.uuid4()
obj.present(dict(task_id=i, last=False))
obj.present(dict(task_id=i, last=False)) # type: ignore
assert obj.active()
obj.present(dict(task_id=i, last=False))
obj.present(dict(task_id=i, last=False)) # type: ignore
assert obj.active()
obj.present(dict(task_id=j, last=False))
obj.present(dict(task_id=j, last=False)) # type: ignore
assert obj.active()
obj.present(dict(task_id=j, last=False))
obj.present(dict(task_id=j, last=False)) # type: ignore
assert obj.active()
obj.present(dict(task_id=i, last=True))
obj.present(dict(task_id=i, last=True)) # type: ignore
assert obj.active()
obj.present(dict(task_id=j, last=True))
obj.present(dict(task_id=j, last=True)) # type: ignore
assert not obj.active()


Expand Down
136 changes: 0 additions & 136 deletions tests/progress_report/test_report_complement.py

This file was deleted.

Loading

0 comments on commit e282fdc

Please sign in to comment.