MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / tqdm_rich

Class tqdm_rich

pager_lib/tqdm/rich.py:72–141  ·  view source on GitHub ↗

Experimental rich.progress GUI version of tqdm!

Source from the content-addressed store, hash-verified

70
71
72class tqdm_rich(std_tqdm): # pragma: no cover
73 """Experimental rich.progress GUI version of tqdm!"""
74 # TODO: @classmethod: write()?
75 def __init__(self, *args, **kwargs):
76 """
77 This class accepts the following parameters *in addition* to
78 the parameters accepted by `tqdm`.
79
80 Parameters
81 ----------
82 progress : tuple, optional
83 arguments for `rich.progress.Progress()`.
84 options : dict, optional
85 keyword arguments for `rich.progress.Progress()`.
86 """
87 kwargs = kwargs.copy()
88 kwargs['gui'] = True
89 # convert disable = None to False
90 kwargs['disable'] = bool(kwargs.get('disable', False))
91 progress = kwargs.pop('progress', None)
92 options = kwargs.pop('options', {}).copy()
93 super().__init__(*args, **kwargs)
94
95 if self.disable:
96 return
97
98 warn("rich is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
99 d = self.format_dict
100 if progress is None:
101 progress = (
102 "[progress.description]{task.description}"
103 "[progress.percentage]{task.percentage:>4.0f}%",
104 BarColumn(bar_width=None),
105 FractionColumn(
106 unit_scale=d['unit_scale'], unit_divisor=d['unit_divisor']),
107 "[", TimeElapsedColumn(), "<", TimeRemainingColumn(),
108 ",", RateColumn(unit=d['unit'], unit_scale=d['unit_scale'],
109 unit_divisor=d['unit_divisor']), "]"
110 )
111 options.setdefault('transient', not self.leave)
112 self._prog = Progress(*progress, **options)
113 self._prog.__enter__()
114 self._task_id = self._prog.add_task(self.desc or "", **d)
115
116 def close(self):
117 if self.disable:
118 return
119 self.display() # print 100%, vis #1306
120 super().close()
121 self._prog.__exit__(None, None, None)
122
123 def clear(self, *_, **__):
124 pass
125
126 def display(self, *_, **__):
127 if not hasattr(self, '_prog'):
128 return
129 self._prog.update(self._task_id, completed=self.n, description=self.desc)

Callers 1

trrangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected