Skip to content

Commit

Permalink
Merge pull request #52 from alphatwirl/dev
Browse files Browse the repository at this point in the history
Rename `taskid` to `task_id` for spellchecker
  • Loading branch information
TaiSakuma authored Jun 9, 2024
2 parents 71513dc + 1e74a71 commit ac9f971
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 117 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@
"spyder",
"starmap",
"superfences",
"taskid"
]
}
6 changes: 3 additions & 3 deletions atpbar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _report_start(self) -> None:
if self.reporter is None:
return
try:
report = Report(taskid=self.id_, name=self.name, done=0, total=self.len_)
report = Report(task_id=self.id_, name=self.name, done=0, total=self.len_)
self.reporter.report(report)
except BaseException:
pass
Expand All @@ -90,7 +90,7 @@ def _report_progress(self, i: int) -> None:
if self.reporter is None:
return
try:
report = Report(taskid=self.id_, done=(i + 1))
report = Report(task_id=self.id_, done=(i + 1))
self.reporter.report(report)
except BaseException:
pass
Expand All @@ -113,7 +113,7 @@ def report_last(pbar: Atpbar[T]) -> Iterator[None]:
if pbar.reporter is None:
return
try:
report = Report(taskid=pbar.id_, first=False, last=True)
report = Report(task_id=pbar.id_, first=False, last=True)
pbar.reporter.report(report)
except BaseException:
pass
20 changes: 10 additions & 10 deletions atpbar/presentation/barjupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def _create_widgets(self) -> None:
self.container_widget = widgets.VBox()
display(self.container_widget)

for taskid in self._new_task_ids:
report = self._report_dict[taskid]
for task_id in self._new_task_ids:
report = self._report_dict[task_id]
self._create_widget(report)

def _create_widget(self, report: Report) -> None:
Expand All @@ -50,13 +50,13 @@ def _create_widget(self, report: Report) -> None:
self.container_widget.children = (
self.complete_box_list + self.active_box_list
)
self.widget_dict[report['taskid']] = (box, bar, label)
self.widget_dict[report['task_id']] = (box, bar, label)

def _update_widgets(self) -> None:
for taskid in (
for task_id in (
self._finishing_task_ids + self._active_task_ids + self._new_task_ids
):
report = self._report_dict[taskid]
report = self._report_dict[task_id]
self._update_widget(report)

self._reorder_widgets(report)
Expand All @@ -73,17 +73,17 @@ def _update_widget(self, report: Report) -> None:
percent = round(percent * 100, 2)
percent_fmt = '{:6.2f}%'.format(percent)

box = self.widget_dict[report['taskid']][0]
box = self.widget_dict[report['task_id']][0]
box # to silence not-used warning

bar = self.widget_dict[report['taskid']][1]
bar = self.widget_dict[report['task_id']][1]
bar.value = report['done']
bar.max = report['total']
bar.description = percent_fmt
if report['last']:
bar.bar_style = 'success'

label = self.widget_dict[report['taskid']][2]
label = self.widget_dict[report['task_id']][2]
name_field_length = 32
percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
bar = (':' * int(percent * 40)).ljust(40, ' ')
Expand All @@ -94,8 +94,8 @@ def _update_widget(self, report: Report) -> None:
)

def _reorder_widgets(self, report: Report) -> None:
for taskid in self._finishing_task_ids:
box, bar, label = self.widget_dict[taskid]
for task_id in self._finishing_task_ids:
box, bar, label = self.widget_dict[task_id]
if box in self.active_box_list:
self.active_box_list.remove(box)
self.complete_box_list.append(box)
Expand Down
8 changes: 4 additions & 4 deletions atpbar/presentation/bartty.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def _erase_active_bars(self) -> None:

def _compose_just_finished_bars(self) -> None:
self.just_finished_bars = [
self._compose_bar_from_taskid(i) for i in self._finishing_task_ids
self._compose_bar_from_task_id(i) for i in self._finishing_task_ids
]

def _compose_active_bars(self) -> None:
self.active_bars = [
self._compose_bar_from_taskid(i)
self._compose_bar_from_task_id(i)
for i in self._active_task_ids + self._new_task_ids
]

def _compose_bar_from_taskid(self, taskid: UUID) -> str:
report = self._report_dict[taskid]
def _compose_bar_from_task_id(self, task_id: UUID) -> str:
report = self._report_dict[task_id]
return self._compose_bar_from_report(report)

def _compose_bar_from_report(self, report: Report) -> str:
Expand Down
20 changes: 10 additions & 10 deletions atpbar/presentation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,38 @@ def _present(self, report: Report) -> None:

def _register_report(self, report: Report) -> bool:

taskid = report['taskid']
task_id = report['task_id']

if taskid in self._complete_task_ids:
if task_id in self._complete_task_ids:
return False

self._report_dict[taskid] = report
self._report_dict[task_id] = report

if taskid in self._finishing_task_ids:
if task_id in self._finishing_task_ids:
return True

if report['last']:
try:
self._active_task_ids.remove(taskid)
self._active_task_ids.remove(task_id)
except ValueError:
pass

try:
self._new_task_ids.remove(taskid)
self._new_task_ids.remove(task_id)
except ValueError:
pass

self._finishing_task_ids.append(taskid)
self._finishing_task_ids.append(task_id)

return True

if taskid in self._active_task_ids:
if task_id in self._active_task_ids:
return True

if taskid in self._new_task_ids:
if task_id in self._new_task_ids:
return True

self._new_task_ids.append(taskid)
self._new_task_ids.append(task_id)
return True

def _update_registry(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions atpbar/presentation/txtprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def present(self, report: Report) -> None:

self._present(report)

self.last_time_map[report['taskid']] = self._time()
self.last_time_map[report['task_id']] = self._time()

def _present(self, report: Report) -> None:
time_ = time.strftime('%m/%d %H:%M', time.localtime(time.time()))
Expand All @@ -48,10 +48,10 @@ def _need_to_present_(self, report: Report) -> bool:
if report['last']:
return True

if report['taskid'] not in self.last_time_map:
if report['task_id'] not in self.last_time_map:
return True

if self._time() - self.last_time_map[report['taskid']] > self.interval:
if self._time() - self.last_time_map[report['task_id']] > self.interval:
return True

return False
Expand Down
20 changes: 10 additions & 10 deletions atpbar/progress_report/complement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ProgressReportComplementer:
Parameters
----------
report : Report
A report must always include `taskid`. The first report for a task must
A report must always include `task_id`. The first report for a task must
include `done`, `total`, and 'name'. The `first` and `last` will be
automatically determined if not given.
Expand All @@ -22,17 +22,17 @@ def __init__(self) -> None:
self.previous_reports = dict[UUID, Report]()

def __call__(self, report: Report) -> None:
taskid = report['taskid']
if taskid in self.previous_reports:
self._complement(taskid, report)
task_id = report['task_id']
if task_id in self.previous_reports:
self._complement(task_id, report)
self._first(report)
self._last(report)
self._store(taskid, report.copy())
self._store(task_id, report.copy())

def _complement(self, taskid: UUID, report: Report) -> None:
def _complement(self, task_id: UUID, report: Report) -> None:
report_copy = report.copy()
report.update(Report(taskid=taskid))
report.update(self.previous_reports[taskid])
report.update(Report(task_id=task_id))
report.update(self.previous_reports[task_id])
report.update(report_copy)

def _first(self, report: Report) -> None:
Expand All @@ -45,7 +45,7 @@ def _last(self, report: Report) -> None:
return
report['last'] = report['done'] >= report['total']

def _store(self, taskid: UUID, report: Report) -> None:
def _store(self, task_id: UUID, report: Report) -> None:
report.pop('first', None)
report.pop('last', None)
self.previous_reports[taskid] = report
self.previous_reports[task_id] = report
4 changes: 2 additions & 2 deletions atpbar/progress_report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Report(TypedDict, total=False):
Parameters
----------
taskid : immutable
task_id : immutable
The unique task ID.
done : int
The number of the iterations done so far
Expand All @@ -30,7 +30,7 @@ class Report(TypedDict, total=False):
TODO: Use typing.Required for Python 3.11 and above
'''

taskid: UUID
task_id: UUID
done: int
total: int
name: str
Expand Down
6 changes: 3 additions & 3 deletions atpbar/progress_report/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def report(self, report: Report) -> None:

self.queue.put(report)

self.last_time[report['taskid']] = time.time()
self.last_time[report['task_id']] = time.time()

def _need_to_report(self, report: Report) -> bool:

Expand All @@ -91,10 +91,10 @@ def _need_to_report(self, report: Report) -> bool:
if report['last']:
return True

if report['taskid'] not in self.last_time:
if report['task_id'] not in self.last_time:
return True

if time.time() - self.last_time[report['taskid']] > self.interval:
if time.time() - self.last_time[report['task_id']] > self.interval:
return True

return False
2 changes: 1 addition & 1 deletion tests/presentation/test_ProgressPrint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_repr() -> None:
def test_report(capsys: pytest.CaptureFixture) -> None:
obj = ProgressPrint()
i = uuid.uuid4()
report = Report(taskid=i, name='task1', done=0, total=10, first=True, last=False)
report = Report(task_id=i, name='task1', done=0, total=10, first=True, last=False)
obj.present(report)
captured = capsys.readouterr()
stdout_lines = captured.out.strip().split('\n')
Expand Down
32 changes: 16 additions & 16 deletions tests/presentation/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ def test_repr(obj: MockProgressBar) -> None:
def test_present(obj: Presentation) -> None:
i = uuid.uuid4()
j = uuid.uuid4()
obj.present(dict(taskid=i, last=False))
obj.present(dict(task_id=i, last=False))
assert obj.active()
obj.present(dict(taskid=i, last=False))
obj.present(dict(task_id=i, last=False))
assert obj.active()
obj.present(dict(taskid=j, last=False))
obj.present(dict(task_id=j, last=False))
assert obj.active()
obj.present(dict(taskid=j, last=False))
obj.present(dict(task_id=j, last=False))
assert obj.active()
obj.present(dict(taskid=i, last=True))
obj.present(dict(task_id=i, last=True))
assert obj.active()
obj.present(dict(taskid=j, last=True))
obj.present(dict(task_id=j, last=True))
assert not obj.active()


params = [
##
pytest.param(dict(taskid=1, last=False), [], [], [], [], [1], [], [], [], True),
pytest.param(dict(taskid=1, last=False), [1], [], [], [], [1], [], [], [], True),
pytest.param(dict(taskid=1, last=False), [], [1], [], [], [], [1], [], [], True),
pytest.param(dict(taskid=1, last=False), [], [], [1], [], [], [], [1], [], True),
pytest.param(dict(taskid=1, last=False), [], [], [], [1], [], [], [], [1], False),
pytest.param(dict(task_id=1, last=False), [], [], [], [], [1], [], [], [], True),
pytest.param(dict(task_id=1, last=False), [1], [], [], [], [1], [], [], [], True),
pytest.param(dict(task_id=1, last=False), [], [1], [], [], [], [1], [], [], True),
pytest.param(dict(task_id=1, last=False), [], [], [1], [], [], [], [1], [], True),
pytest.param(dict(task_id=1, last=False), [], [], [], [1], [], [], [], [1], False),
##
pytest.param(dict(taskid=1, last=True), [], [], [], [], [], [], [1], [], True),
pytest.param(dict(taskid=1, last=True), [1], [], [], [], [], [], [1], [], True),
pytest.param(dict(taskid=1, last=True), [], [1], [], [], [], [], [1], [], True),
pytest.param(dict(taskid=1, last=True), [], [], [1], [], [], [], [1], [], True),
pytest.param(dict(taskid=1, last=True), [], [], [], [1], [], [], [], [1], False),
pytest.param(dict(task_id=1, last=True), [], [], [], [], [], [], [1], [], True),
pytest.param(dict(task_id=1, last=True), [1], [], [], [], [], [], [1], [], True),
pytest.param(dict(task_id=1, last=True), [], [1], [], [], [], [], [1], [], True),
pytest.param(dict(task_id=1, last=True), [], [], [1], [], [], [], [1], [], True),
pytest.param(dict(task_id=1, last=True), [], [], [], [1], [], [], [], [1], False),
]
param_names = (
'report, '
Expand Down
26 changes: 16 additions & 10 deletions tests/presentation/test_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@ def test_presentation(Class: type[Presentation]) -> None:
obj = Class()
repr(obj)
obj.active()
obj.present(dict(name='task1', done=0, total=10, taskid=i, first=True, last=False))
obj.present(dict(name='task1', done=2, total=10, taskid=i, first=False, last=False))
obj.present(dict(name='task1', done=0, total=10, task_id=i, first=True, last=False))
obj.present(
dict(name='task1', done=2, total=10, task_id=i, first=False, last=False)
)
obj.active()
obj.present(dict(name='task1', done=0, total=5, taskid=j, first=True, last=False))
obj.present(dict(name='task1', done=3, total=5, taskid=j, first=False, last=False))
obj.present(dict(name='task1', done=0, total=5, task_id=j, first=True, last=False))
obj.present(dict(name='task1', done=3, total=5, task_id=j, first=False, last=False))
obj.active()
obj.present(dict(name='task1', done=10, total=10, taskid=i, first=False, last=True))
obj.present(
dict(name='task1', done=10, total=10, task_id=i, first=False, last=True)
)
obj.active()
obj.present(dict(name='task1', done=5, total=5, taskid=j, first=False, last=True))
obj.present(dict(name='task1', done=5, total=5, task_id=j, first=False, last=True))
obj.active()
obj.active()
obj.present(dict(name='task1', done=10, total=10, taskid=i, first=False, last=True))
obj.present(
dict(name='task1', done=10, total=10, task_id=i, first=False, last=True)
)
obj.active()


Expand All @@ -60,7 +66,7 @@ def test_time_track(Class: type[Presentation]) -> None:
name='task1',
done=0,
total=10,
taskid=i,
task_id=i,
first=True,
last=False,
)
Expand All @@ -70,7 +76,7 @@ def test_time_track(Class: type[Presentation]) -> None:
name='task1',
done=2,
total=10,
taskid=i,
task_id=i,
first=False,
last=False,
)
Expand All @@ -80,7 +86,7 @@ def test_time_track(Class: type[Presentation]) -> None:
name='task1',
done=10,
total=10,
taskid=i,
task_id=i,
first=False,
last=True,
)
Expand Down
Loading

0 comments on commit ac9f971

Please sign in to comment.