Skip to content

Commit

Permalink
Merge pull request #43 from alphatwirl/dev
Browse files Browse the repository at this point in the history
Replace double quotes with single quotes
  • Loading branch information
TaiSakuma authored May 26, 2024
2 parents e8c8d69 + 6cf8a45 commit a3d8d2f
Show file tree
Hide file tree
Showing 32 changed files with 275 additions and 275 deletions.
2 changes: 1 addition & 1 deletion atpbar/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.1"
__version__ = '2.0.1'
14 changes: 7 additions & 7 deletions atpbar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__all__ = [
"atpbar",
"find_reporter",
"register_reporter",
"flush",
"flushing",
"disable",
"__version__",
'atpbar',
'find_reporter',
'register_reporter',
'flush',
'flushing',
'disable',
'__version__',
]
from .__about__ import __version__
from .funcs import disable, find_reporter, flush, flushing, register_reporter
Expand Down
4 changes: 2 additions & 2 deletions atpbar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def atpbar(iterable: Iterable[T], /, name: Optional[str] = None) -> Iterable[T]:
len_ = len(iterable) # type: ignore
except TypeError:
logger = logging.getLogger(__name__)
logger.warning("length is unknown: {!r}".format(iterable))
logger.warning("atpbar is turned off")
logger.warning('length is unknown: {!r}'.format(iterable))
logger.warning('atpbar is turned off')
return iterable

if name is None:
Expand Down
44 changes: 22 additions & 22 deletions atpbar/presentation/barjupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self) -> None:
]()

def __repr__(self) -> str:
return "{}()".format(self.__class__.__name__)
return '{}()'.format(self.__class__.__name__)

def _present(self, report: Report) -> None:
self._create_widgets()
Expand All @@ -36,21 +36,21 @@ def _create_widgets(self) -> None:

def _create_widget(self, report: Report) -> None:
bar = widgets.IntProgress(
value=report["done"],
value=report['done'],
min=0,
max=report["total"],
description="",
bar_style="", # 'success', 'info', 'warning', 'danger' or ''
orientation="horizontal",
max=report['total'],
description='',
bar_style='', # 'success', 'info', 'warning', 'danger' or ''
orientation='horizontal',
)
label = widgets.HTML(value="")
label = widgets.HTML(value='')
box = widgets.HBox([bar, label])
self.active_box_list.append(box)
if self.container_widget is not 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['taskid']] = (box, bar, label)

def _update_widgets(self) -> None:
for taskid in (
Expand All @@ -69,28 +69,28 @@ def _update_widgets(self) -> None:

def _update_widget(self, report: Report) -> None:

percent = float(report["done"]) / report["total"] if report["total"] > 0 else 1
percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
percent = round(percent * 100, 2)
percent_fmt = "{:6.2f}%".format(percent)
percent_fmt = '{:6.2f}%'.format(percent)

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

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

label = self.widget_dict[report["taskid"]][2]
label = self.widget_dict[report['taskid']][2]
name_field_length = 32
percent = float(report["done"]) / report["total"] if report["total"] > 0 else 1
bar = (":" * int(percent * 40)).ljust(40, " ")
percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
bar = (':' * int(percent * 40)).ljust(40, ' ')
percent = round(percent * 100, 2)
name = report["name"][0:name_field_length]
label.value = "<pre> | {:8d} / {:8d} |: {:<{}s}</pre>".format(
report["done"], report["total"], name, name_field_length
name = report['name'][0:name_field_length]
label.value = '<pre> | {:8d} / {:8d} |: {:<{}s}</pre>'.format(
report['done'], report['total'], name, name_field_length
)

def _reorder_widgets(self, report: Report) -> None:
Expand Down
30 changes: 15 additions & 15 deletions atpbar/presentation/bartty.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self) -> None:
self.just_finished_bars = list[str]()

def __repr__(self) -> str:
return "{}()".format(self.__class__.__name__)
return '{}()'.format(self.__class__.__name__)

def _get_width(self) -> int:
try:
Expand All @@ -40,7 +40,7 @@ def _write(self, s: str, out: TextIO) -> None:
return
self._erase_active_bars()
out.write(s.rstrip())
out.write("\n")
out.write('\n')
out.flush()
self._draw_active_bars()

Expand All @@ -51,7 +51,7 @@ def _erase_active_bars(self) -> None:
if n_lines == 0:
return

code = "\033[1G" + "\033[A" * (n_lines - 1) + "\033[0J"
code = '\033[1G' + '\033[A' * (n_lines - 1) + '\033[0J'
# '\033[1G' move the cursor to the beginning of the line
# '\033[A' move the cursor up
# '\033[0J' clear from cursor to end of screen
Expand All @@ -76,37 +76,37 @@ def _compose_bar_from_taskid(self, taskid: UUID) -> str:

def _compose_bar_from_report(self, report: Report) -> str:

percent = float(report["done"]) / report["total"] if report["total"] > 0 else 1
percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
# e.g., 0.7143369818769065

bar = (":" * int(percent * 40)).ljust(40, " ")
# e.g., ":::::::::::::::::::::::::::: "
bar = (':' * int(percent * 40)).ljust(40, ' ')
# e.g., ':::::::::::::::::::::::::::: '

percent = round(percent * 100, 2)
# e.g., 71.43

format = " {percent:6.2f}% {bar:s} | {done:8d} / {total:8d} |: {name} "
format = ' {percent:6.2f}% {bar:s} | {done:8d} / {total:8d} |: {name} '

ret = format.format(
percent=percent,
bar=bar,
done=report["done"],
total=report["total"],
name=report["name"],
done=report['done'],
total=report['total'],
name=report['name'],
)
# e.g., " 71.43% :::::::::::::::::::::::::::: | 3981 / 5573 |: task name "
# e.g., ' 71.43% :::::::::::::::::::::::::::: | 3981 / 5573 |: task name '

ret = ret[: self.width].ljust(self.width, " ")
# e.g., " 71.43% :::::::::::::::::::::::::::: | 3981 / 5573 |: task na"
ret = ret[: self.width].ljust(self.width, ' ')
# e.g., ' 71.43% :::::::::::::::::::::::::::: | 3981 / 5573 |: task na'

return ret

def _draw_just_finished_bars(self) -> None:
if self.just_finished_bars:
self.out.write("\n".join(self.just_finished_bars) + "\n")
self.out.write('\n'.join(self.just_finished_bars) + '\n')
self.out.flush()

def _draw_active_bars(self) -> None:
if self.active_bars:
self.out.write("\n".join(self.active_bars))
self.out.write('\n'.join(self.active_bars))
self.out.flush()
6 changes: 3 additions & 3 deletions atpbar/presentation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _present(self, report: Report) -> None:

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

taskid = report["taskid"]
taskid = report['taskid']

if taskid in self._complete_task_ids:
return False
Expand All @@ -63,7 +63,7 @@ def _register_report(self, report: Report) -> bool:
if taskid in self._finishing_task_ids:
return True

if report["last"]:
if report['last']:
try:
self._active_task_ids.remove(taskid)
except ValueError:
Expand Down Expand Up @@ -123,5 +123,5 @@ def _stderr_write(self, s: str) -> None:

def _write(self, s: str, out: TextIO) -> None:
out.write(s.rstrip())
out.write("\n")
out.write('\n')
out.flush()
2 changes: 1 addition & 1 deletion atpbar/presentation/detect/jupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def is_jupyter_notebook() -> bool:
return False

try:
if "IPKernelApp" not in get_ipython().config:
if 'IPKernelApp' not in get_ipython().config:
return False
except:
return False
Expand Down
8 changes: 4 additions & 4 deletions atpbar/presentation/detect/spy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def is_spyder_ide() -> bool:
return False

try:
if "IPKernelApp" not in get_ipython().config:
if 'IPKernelApp' not in get_ipython().config:
return False
except:
return False

if "SPYDER_ARGS" not in os.environ:
if 'SPYDER_ARGS' not in os.environ:
return False

min_n_spy_var = 15 # A possible minimum number of the environmental
# variables that start with "SPY_" on Spyder IDE.
n_spy_var = len([k for k in os.environ.keys() if k.startswith("SPY_")])
# variables that start with 'SPY_' on Spyder IDE.
n_spy_var = len([k for k in os.environ.keys() if k.startswith('SPY_')])
if n_spy_var < min_n_spy_var:
return False

Expand Down
26 changes: 13 additions & 13 deletions atpbar/presentation/txtprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self) -> None:
self.last_time_map = dict[UUID, float]()

def __repr__(self) -> str:
return "{}()".format(self.__class__.__name__)
return '{}()'.format(self.__class__.__name__)

def present(self, report: Report) -> None:

Expand All @@ -23,35 +23,35 @@ def present(self, report: Report) -> None:

self._present(report)

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

def _present(self, report: Report) -> None:
time_ = time.strftime("%m/%d %H:%M", time.localtime(time.time()))
percent = float(report["done"]) / report["total"] if report["total"] > 0 else 1
time_ = time.strftime('%m/%d %H:%M', time.localtime(time.time()))
percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
percent = round(percent * 100, 2)
line = "{time} : {done:8d} / {total:8d} ({percent:6.2f}%): {name} ".format(
line = '{time} : {done:8d} / {total:8d} ({percent:6.2f}%): {name} '.format(
time=time_,
done=report["done"],
total=report["total"],
done=report['done'],
total=report['total'],
percent=percent,
name=report["name"],
name=report['name'],
)
line = "{}\n".format(line)
line = '{}\n'.format(line)
self.out.write(line)
self.out.flush()

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

if report["first"]:
if report['first']:
return True

if report["last"]:
if report['last']:
return True

if report["taskid"] not in self.last_time_map:
if report['taskid'] 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['taskid']] > self.interval:
return True

return False
Expand Down
10 changes: 5 additions & 5 deletions atpbar/progress_report/complement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self) -> None:
self.previous_reports = dict[UUID, Report]()

def __call__(self, report: Report) -> None:
taskid = report["taskid"]
taskid = report['taskid']
if taskid in self.previous_reports:
self._complement(taskid, report)
self._first(report)
Expand All @@ -36,14 +36,14 @@ def _complement(self, taskid: UUID, report: Report) -> None:
report.update(report_copy)

def _first(self, report: Report) -> None:
if "first" in report:
if 'first' in report:
return
report["first"] = report["done"] == 0
report['first'] = report['done'] == 0

def _last(self, report: Report) -> None:
if "last" in report:
if 'last' in report:
return
report["last"] = report["done"] >= report["total"]
report['last'] = report['done'] >= report['total']

def _store(self, taskid: UUID, report: Report) -> None:
report.pop('first', None)
Expand Down
12 changes: 6 additions & 6 deletions atpbar/progress_report/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
self.stream_redirection_enablaed = True

def __repr__(self) -> str:
return "{}(queue={!r}, interval={!r})".format(
return '{}(queue={!r}, interval={!r})'.format(
self.__class__.__name__, self.queue, self.interval
)

Expand All @@ -81,20 +81,20 @@ def report(self, report: Report) -> None:

self.queue.put(report)

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

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

if report["first"]:
if report['first']:
return True

if report["last"]:
if report['last']:
return True

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

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

return False
Loading

0 comments on commit a3d8d2f

Please sign in to comment.