Add loan-advisor-agent
Browse files- loan-advisor-agent/.venv/Lib/site-packages/tqdm/__init__.py +38 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/__main__.py +3 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_main.py +9 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_monitor.py +95 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm.py +9 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_gui.py +9 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_notebook.py +9 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_pandas.py +24 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/_utils.py +11 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/asyncio.py +93 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/auto.py +40 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/autonotebook.py +29 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/cli.py +324 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/completion.sh +19 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/__init__.py +91 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/bells.py +26 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/concurrent.py +105 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/discord.py +156 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/itertools.py +35 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/logging.py +126 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/slack.py +120 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/telegram.py +153 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/utils_worker.py +38 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/dask.py +44 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/gui.py +179 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/keras.py +122 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/notebook.py +315 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/rich.py +151 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/std.py +1524 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/tk.py +196 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/tqdm.1 +243 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/utils.py +399 -0
- loan-advisor-agent/.venv/Lib/site-packages/tqdm/version.py +10 -0
loan-advisor-agent/.venv/Lib/site-packages/tqdm/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._monitor import TMonitor, TqdmSynchronisationWarning
|
| 2 |
+
from ._tqdm_pandas import tqdm_pandas
|
| 3 |
+
from .cli import main # TODO: remove in v5.0.0
|
| 4 |
+
from .gui import tqdm as tqdm_gui # TODO: remove in v5.0.0
|
| 5 |
+
from .gui import trange as tgrange # TODO: remove in v5.0.0
|
| 6 |
+
from .std import (
|
| 7 |
+
TqdmDeprecationWarning, TqdmExperimentalWarning, TqdmKeyError, TqdmMonitorWarning,
|
| 8 |
+
TqdmTypeError, TqdmWarning, tqdm, trange)
|
| 9 |
+
from .version import __version__
|
| 10 |
+
|
| 11 |
+
__all__ = ['tqdm', 'tqdm_gui', 'trange', 'tgrange', 'tqdm_pandas',
|
| 12 |
+
'tqdm_notebook', 'tnrange', 'main', 'TMonitor',
|
| 13 |
+
'TqdmTypeError', 'TqdmKeyError',
|
| 14 |
+
'TqdmWarning', 'TqdmDeprecationWarning',
|
| 15 |
+
'TqdmExperimentalWarning',
|
| 16 |
+
'TqdmMonitorWarning', 'TqdmSynchronisationWarning',
|
| 17 |
+
'__version__']
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def tqdm_notebook(*args, **kwargs): # pragma: no cover
|
| 21 |
+
"""See tqdm.notebook.tqdm for full documentation"""
|
| 22 |
+
from warnings import warn
|
| 23 |
+
|
| 24 |
+
from .notebook import tqdm as _tqdm_notebook
|
| 25 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 26 |
+
"Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`",
|
| 27 |
+
TqdmDeprecationWarning, stacklevel=2)
|
| 28 |
+
return _tqdm_notebook(*args, **kwargs)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def tnrange(*args, **kwargs): # pragma: no cover
|
| 32 |
+
"""Shortcut for `tqdm.notebook.tqdm(range(*args), **kwargs)`."""
|
| 33 |
+
from warnings import warn
|
| 34 |
+
|
| 35 |
+
from .notebook import trange as _tnrange
|
| 36 |
+
warn("Please use `tqdm.notebook.trange` instead of `tqdm.tnrange`",
|
| 37 |
+
TqdmDeprecationWarning, stacklevel=2)
|
| 38 |
+
return _tnrange(*args, **kwargs)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/__main__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .cli import main
|
| 2 |
+
|
| 3 |
+
main()
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_main.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .cli import * # NOQA
|
| 4 |
+
from .cli import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.cli.*` instead of `tqdm._main.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_monitor.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import atexit
|
| 2 |
+
from threading import Event, Thread, current_thread
|
| 3 |
+
from time import time
|
| 4 |
+
from warnings import warn
|
| 5 |
+
|
| 6 |
+
__all__ = ["TMonitor", "TqdmSynchronisationWarning"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TqdmSynchronisationWarning(RuntimeWarning):
|
| 10 |
+
"""tqdm multi-thread/-process errors which may cause incorrect nesting
|
| 11 |
+
but otherwise no adverse effects"""
|
| 12 |
+
pass
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TMonitor(Thread):
|
| 16 |
+
"""
|
| 17 |
+
Monitoring thread for tqdm bars.
|
| 18 |
+
Monitors if tqdm bars are taking too much time to display
|
| 19 |
+
and readjusts miniters automatically if necessary.
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
----------
|
| 23 |
+
tqdm_cls : class
|
| 24 |
+
tqdm class to use (can be core tqdm or a submodule).
|
| 25 |
+
sleep_interval : float
|
| 26 |
+
Time to sleep between monitoring checks.
|
| 27 |
+
"""
|
| 28 |
+
_test = {} # internal vars for unit testing
|
| 29 |
+
|
| 30 |
+
def __init__(self, tqdm_cls, sleep_interval):
|
| 31 |
+
Thread.__init__(self)
|
| 32 |
+
self.daemon = True # kill thread when main killed (KeyboardInterrupt)
|
| 33 |
+
self.woken = 0 # last time woken up, to sync with monitor
|
| 34 |
+
self.tqdm_cls = tqdm_cls
|
| 35 |
+
self.sleep_interval = sleep_interval
|
| 36 |
+
self._time = self._test.get("time", time)
|
| 37 |
+
self.was_killed = self._test.get("Event", Event)()
|
| 38 |
+
atexit.register(self.exit)
|
| 39 |
+
self.start()
|
| 40 |
+
|
| 41 |
+
def exit(self):
|
| 42 |
+
self.was_killed.set()
|
| 43 |
+
if self is not current_thread():
|
| 44 |
+
self.join()
|
| 45 |
+
return self.report()
|
| 46 |
+
|
| 47 |
+
def get_instances(self):
|
| 48 |
+
# returns a copy of started `tqdm_cls` instances
|
| 49 |
+
return [i for i in self.tqdm_cls._instances.copy()
|
| 50 |
+
# Avoid race by checking that the instance started
|
| 51 |
+
if hasattr(i, 'start_t')]
|
| 52 |
+
|
| 53 |
+
def run(self):
|
| 54 |
+
cur_t = self._time()
|
| 55 |
+
while True:
|
| 56 |
+
# After processing and before sleeping, notify that we woke
|
| 57 |
+
# Need to be done just before sleeping
|
| 58 |
+
self.woken = cur_t
|
| 59 |
+
# Sleep some time...
|
| 60 |
+
self.was_killed.wait(self.sleep_interval)
|
| 61 |
+
# Quit if killed
|
| 62 |
+
if self.was_killed.is_set():
|
| 63 |
+
return
|
| 64 |
+
# Then monitor!
|
| 65 |
+
# Acquire lock (to access _instances)
|
| 66 |
+
with self.tqdm_cls.get_lock():
|
| 67 |
+
cur_t = self._time()
|
| 68 |
+
# Check tqdm instances are waiting too long to print
|
| 69 |
+
instances = self.get_instances()
|
| 70 |
+
for instance in instances:
|
| 71 |
+
# Check event in loop to reduce blocking time on exit
|
| 72 |
+
if self.was_killed.is_set():
|
| 73 |
+
return
|
| 74 |
+
# Only if mininterval > 1 (else iterations are just slow)
|
| 75 |
+
# and last refresh exceeded maxinterval
|
| 76 |
+
if (
|
| 77 |
+
instance.miniters > 1
|
| 78 |
+
and (cur_t - instance.last_print_t) >= instance.maxinterval
|
| 79 |
+
):
|
| 80 |
+
# force bypassing miniters on next iteration
|
| 81 |
+
# (dynamic_miniters adjusts mininterval automatically)
|
| 82 |
+
instance.miniters = 1
|
| 83 |
+
# Refresh now! (works only for manual tqdm)
|
| 84 |
+
instance.refresh(nolock=True)
|
| 85 |
+
# Remove accidental long-lived strong reference
|
| 86 |
+
del instance
|
| 87 |
+
if instances != self.get_instances(): # pragma: nocover
|
| 88 |
+
warn("Set changed size during iteration" +
|
| 89 |
+
" (see https://github.com/tqdm/tqdm/issues/481)",
|
| 90 |
+
TqdmSynchronisationWarning, stacklevel=2)
|
| 91 |
+
# Remove accidental long-lived strong references
|
| 92 |
+
del instances
|
| 93 |
+
|
| 94 |
+
def report(self):
|
| 95 |
+
return not self.was_killed.is_set()
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .std import * # NOQA
|
| 4 |
+
from .std import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.std.*` instead of `tqdm._tqdm.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_gui.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .gui import * # NOQA
|
| 4 |
+
from .gui import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.gui.*` instead of `tqdm._tqdm_gui.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_notebook.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .notebook import * # NOQA
|
| 4 |
+
from .notebook import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_tqdm_pandas.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
__author__ = "github.com/casperdcl"
|
| 4 |
+
__all__ = ['tqdm_pandas']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def tqdm_pandas(tclass, **tqdm_kwargs):
|
| 8 |
+
"""
|
| 9 |
+
Registers the given `tqdm` instance with
|
| 10 |
+
`pandas.core.groupby.DataFrameGroupBy.progress_apply`.
|
| 11 |
+
"""
|
| 12 |
+
from tqdm import TqdmDeprecationWarning
|
| 13 |
+
|
| 14 |
+
if isinstance(tclass, type) or (getattr(tclass, '__name__', '').startswith(
|
| 15 |
+
'tqdm_')): # delayed adapter case
|
| 16 |
+
TqdmDeprecationWarning(
|
| 17 |
+
"Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm, ...)`.",
|
| 18 |
+
fp_write=getattr(tqdm_kwargs.get('file', None), 'write', sys.stderr.write))
|
| 19 |
+
tclass.pandas(**tqdm_kwargs)
|
| 20 |
+
else:
|
| 21 |
+
TqdmDeprecationWarning(
|
| 22 |
+
"Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm(...))`.",
|
| 23 |
+
fp_write=getattr(tclass.fp, 'write', sys.stderr.write))
|
| 24 |
+
type(tclass).pandas(deprecated_t=tclass)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/_utils.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .std import TqdmDeprecationWarning
|
| 4 |
+
from .utils import ( # NOQA, pylint: disable=unused-import
|
| 5 |
+
CUR_OS, IS_NIX, IS_WIN, RE_ANSI, Comparable, FormatReplace, SimpleTextIOWrapper,
|
| 6 |
+
_environ_cols_wrapper, _is_ascii, _is_utf, _screen_shape_linux, _screen_shape_tput,
|
| 7 |
+
_screen_shape_windows, _screen_shape_wrapper, _supports_unicode, _term_move_up, colorama)
|
| 8 |
+
|
| 9 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 10 |
+
"Please use `tqdm.utils.*` instead of `tqdm._utils.*`",
|
| 11 |
+
TqdmDeprecationWarning, stacklevel=2)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/asyncio.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Asynchronous progressbar decorator for iterators.
|
| 3 |
+
Includes a default `range` iterator printing to `stderr`.
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
>>> from tqdm.asyncio import trange, tqdm
|
| 7 |
+
>>> async for i in trange(10):
|
| 8 |
+
... ...
|
| 9 |
+
"""
|
| 10 |
+
import asyncio
|
| 11 |
+
from sys import version_info
|
| 12 |
+
|
| 13 |
+
from .std import tqdm as std_tqdm
|
| 14 |
+
|
| 15 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 16 |
+
__all__ = ['tqdm_asyncio', 'tarange', 'tqdm', 'trange']
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class tqdm_asyncio(std_tqdm):
|
| 20 |
+
"""
|
| 21 |
+
Asynchronous-friendly version of tqdm.
|
| 22 |
+
"""
|
| 23 |
+
def __init__(self, iterable=None, *args, **kwargs):
|
| 24 |
+
super().__init__(iterable, *args, **kwargs)
|
| 25 |
+
self.iterable_awaitable = False
|
| 26 |
+
if iterable is not None:
|
| 27 |
+
if hasattr(iterable, "__anext__"):
|
| 28 |
+
self.iterable_next = iterable.__anext__
|
| 29 |
+
self.iterable_awaitable = True
|
| 30 |
+
elif hasattr(iterable, "__next__"):
|
| 31 |
+
self.iterable_next = iterable.__next__
|
| 32 |
+
else:
|
| 33 |
+
self.iterable_iterator = iter(iterable)
|
| 34 |
+
self.iterable_next = self.iterable_iterator.__next__
|
| 35 |
+
|
| 36 |
+
def __aiter__(self):
|
| 37 |
+
return self
|
| 38 |
+
|
| 39 |
+
async def __anext__(self):
|
| 40 |
+
try:
|
| 41 |
+
if self.iterable_awaitable:
|
| 42 |
+
res = await self.iterable_next()
|
| 43 |
+
else:
|
| 44 |
+
res = self.iterable_next()
|
| 45 |
+
self.update()
|
| 46 |
+
return res
|
| 47 |
+
except StopIteration:
|
| 48 |
+
self.close()
|
| 49 |
+
raise StopAsyncIteration
|
| 50 |
+
except BaseException:
|
| 51 |
+
self.close()
|
| 52 |
+
raise
|
| 53 |
+
|
| 54 |
+
def send(self, *args, **kwargs):
|
| 55 |
+
return self.iterable.send(*args, **kwargs)
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def as_completed(cls, fs, *, loop=None, timeout=None, total=None, **tqdm_kwargs):
|
| 59 |
+
"""
|
| 60 |
+
Wrapper for `asyncio.as_completed`.
|
| 61 |
+
"""
|
| 62 |
+
if total is None:
|
| 63 |
+
total = len(fs)
|
| 64 |
+
kwargs = {}
|
| 65 |
+
if version_info[:2] < (3, 10):
|
| 66 |
+
kwargs['loop'] = loop
|
| 67 |
+
yield from cls(asyncio.as_completed(fs, timeout=timeout, **kwargs),
|
| 68 |
+
total=total, **tqdm_kwargs)
|
| 69 |
+
|
| 70 |
+
@classmethod
|
| 71 |
+
async def gather(cls, *fs, loop=None, timeout=None, total=None, **tqdm_kwargs):
|
| 72 |
+
"""
|
| 73 |
+
Wrapper for `asyncio.gather`.
|
| 74 |
+
"""
|
| 75 |
+
async def wrap_awaitable(i, f):
|
| 76 |
+
return i, await f
|
| 77 |
+
|
| 78 |
+
ifs = [wrap_awaitable(i, f) for i, f in enumerate(fs)]
|
| 79 |
+
res = [await f for f in cls.as_completed(ifs, loop=loop, timeout=timeout,
|
| 80 |
+
total=total, **tqdm_kwargs)]
|
| 81 |
+
return [i for _, i in sorted(res)]
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def tarange(*args, **kwargs):
|
| 85 |
+
"""
|
| 86 |
+
A shortcut for `tqdm.asyncio.tqdm(range(*args), **kwargs)`.
|
| 87 |
+
"""
|
| 88 |
+
return tqdm_asyncio(range(*args), **kwargs)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# Aliases
|
| 92 |
+
tqdm = tqdm_asyncio
|
| 93 |
+
trange = tarange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/auto.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Enables multiple commonly used features.
|
| 3 |
+
|
| 4 |
+
Method resolution order:
|
| 5 |
+
|
| 6 |
+
- `tqdm.autonotebook` without import warnings
|
| 7 |
+
- `tqdm.asyncio`
|
| 8 |
+
- `tqdm.std` base class
|
| 9 |
+
|
| 10 |
+
Usage:
|
| 11 |
+
>>> from tqdm.auto import trange, tqdm
|
| 12 |
+
>>> for i in trange(10):
|
| 13 |
+
... ...
|
| 14 |
+
"""
|
| 15 |
+
import warnings
|
| 16 |
+
|
| 17 |
+
from .std import TqdmExperimentalWarning
|
| 18 |
+
|
| 19 |
+
with warnings.catch_warnings():
|
| 20 |
+
warnings.simplefilter("ignore", category=TqdmExperimentalWarning)
|
| 21 |
+
from .autonotebook import tqdm as notebook_tqdm
|
| 22 |
+
|
| 23 |
+
from .asyncio import tqdm as asyncio_tqdm
|
| 24 |
+
from .std import tqdm as std_tqdm
|
| 25 |
+
|
| 26 |
+
if notebook_tqdm != std_tqdm:
|
| 27 |
+
class tqdm(notebook_tqdm, asyncio_tqdm): # pylint: disable=inconsistent-mro
|
| 28 |
+
pass
|
| 29 |
+
else:
|
| 30 |
+
tqdm = asyncio_tqdm
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def trange(*args, **kwargs):
|
| 34 |
+
"""
|
| 35 |
+
A shortcut for `tqdm.auto.tqdm(range(*args), **kwargs)`.
|
| 36 |
+
"""
|
| 37 |
+
return tqdm(range(*args), **kwargs)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
__all__ = ["tqdm", "trange"]
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/autonotebook.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Automatically choose between `tqdm.notebook` and `tqdm.std`.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.autonotebook import trange, tqdm
|
| 6 |
+
>>> for i in trange(10):
|
| 7 |
+
... ...
|
| 8 |
+
"""
|
| 9 |
+
import sys
|
| 10 |
+
from warnings import warn
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
get_ipython = sys.modules['IPython'].get_ipython
|
| 14 |
+
if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
|
| 15 |
+
raise ImportError("console")
|
| 16 |
+
from .notebook import WARN_NOIPYW, IProgress
|
| 17 |
+
if IProgress is None:
|
| 18 |
+
from .std import TqdmWarning
|
| 19 |
+
warn(WARN_NOIPYW, TqdmWarning, stacklevel=2)
|
| 20 |
+
raise ImportError('ipywidgets')
|
| 21 |
+
except Exception:
|
| 22 |
+
from .std import tqdm, trange
|
| 23 |
+
else: # pragma: no cover
|
| 24 |
+
from .notebook import tqdm, trange
|
| 25 |
+
from .std import TqdmExperimentalWarning
|
| 26 |
+
warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
|
| 27 |
+
" Use `tqdm.tqdm` instead to force console mode"
|
| 28 |
+
" (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2)
|
| 29 |
+
__all__ = ["tqdm", "trange"]
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/cli.py
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Module version for monitoring CLI pipes (`... | python -m tqdm | ...`).
|
| 3 |
+
"""
|
| 4 |
+
import logging
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
from ast import literal_eval as numeric
|
| 8 |
+
from textwrap import indent
|
| 9 |
+
|
| 10 |
+
from .std import TqdmKeyError, TqdmTypeError, tqdm
|
| 11 |
+
from .version import __version__
|
| 12 |
+
|
| 13 |
+
__all__ = ["main"]
|
| 14 |
+
log = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def cast(val, typ):
|
| 18 |
+
log.debug((val, typ))
|
| 19 |
+
if " or " in typ:
|
| 20 |
+
for t in typ.split(" or "):
|
| 21 |
+
try:
|
| 22 |
+
return cast(val, t)
|
| 23 |
+
except TqdmTypeError:
|
| 24 |
+
pass
|
| 25 |
+
raise TqdmTypeError(f"{val} : {typ}")
|
| 26 |
+
|
| 27 |
+
# sys.stderr.write('\ndebug | `val:type`: `' + val + ':' + typ + '`.\n')
|
| 28 |
+
if typ == 'bool':
|
| 29 |
+
if (val == 'True') or (val == ''):
|
| 30 |
+
return True
|
| 31 |
+
if val == 'False':
|
| 32 |
+
return False
|
| 33 |
+
raise TqdmTypeError(val + ' : ' + typ)
|
| 34 |
+
if typ == 'chr':
|
| 35 |
+
if len(val) == 1:
|
| 36 |
+
return val.encode()
|
| 37 |
+
if re.match(r"^\\\w+$", val):
|
| 38 |
+
return eval(f'"{val}"').encode()
|
| 39 |
+
raise TqdmTypeError(f"{val} : {typ}")
|
| 40 |
+
if typ == 'str':
|
| 41 |
+
return val
|
| 42 |
+
if typ == 'int':
|
| 43 |
+
try:
|
| 44 |
+
return int(val)
|
| 45 |
+
except ValueError as exc:
|
| 46 |
+
raise TqdmTypeError(f"{val} : {typ}") from exc
|
| 47 |
+
if typ == 'float':
|
| 48 |
+
try:
|
| 49 |
+
return float(val)
|
| 50 |
+
except ValueError as exc:
|
| 51 |
+
raise TqdmTypeError(f"{val} : {typ}") from exc
|
| 52 |
+
raise TqdmTypeError(f"{val} : {typ}")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def posix_pipe(fin, fout, delim=b'\\n', buf_size=256,
|
| 56 |
+
callback=lambda float: None, callback_len=True):
|
| 57 |
+
"""
|
| 58 |
+
Params
|
| 59 |
+
------
|
| 60 |
+
fin : binary file with `read(buf_size : int)` method
|
| 61 |
+
fout : binary file with `write` (and optionally `flush`) methods.
|
| 62 |
+
callback : function(float), e.g.: `tqdm.update`
|
| 63 |
+
callback_len : If (default: True) do `callback(len(buffer))`.
|
| 64 |
+
Otherwise, do `callback(data) for data in buffer.split(delim)`.
|
| 65 |
+
"""
|
| 66 |
+
fp_write = fout.write
|
| 67 |
+
|
| 68 |
+
if not delim:
|
| 69 |
+
while True:
|
| 70 |
+
tmp = fin.read(buf_size)
|
| 71 |
+
|
| 72 |
+
# flush at EOF
|
| 73 |
+
if not tmp:
|
| 74 |
+
getattr(fout, 'flush', lambda: None)()
|
| 75 |
+
return
|
| 76 |
+
|
| 77 |
+
fp_write(tmp)
|
| 78 |
+
callback(len(tmp))
|
| 79 |
+
# return
|
| 80 |
+
|
| 81 |
+
buf = b''
|
| 82 |
+
len_delim = len(delim)
|
| 83 |
+
# n = 0
|
| 84 |
+
while True:
|
| 85 |
+
tmp = fin.read(buf_size)
|
| 86 |
+
|
| 87 |
+
# flush at EOF
|
| 88 |
+
if not tmp:
|
| 89 |
+
if buf:
|
| 90 |
+
fp_write(buf)
|
| 91 |
+
if callback_len:
|
| 92 |
+
# n += 1 + buf.count(delim)
|
| 93 |
+
callback(1 + buf.count(delim))
|
| 94 |
+
else:
|
| 95 |
+
for i in buf.split(delim):
|
| 96 |
+
callback(i)
|
| 97 |
+
getattr(fout, 'flush', lambda: None)()
|
| 98 |
+
return # n
|
| 99 |
+
|
| 100 |
+
while True:
|
| 101 |
+
i = tmp.find(delim)
|
| 102 |
+
if i < 0:
|
| 103 |
+
buf += tmp
|
| 104 |
+
break
|
| 105 |
+
fp_write(buf + tmp[:i + len(delim)])
|
| 106 |
+
# n += 1
|
| 107 |
+
callback(1 if callback_len else (buf + tmp[:i]))
|
| 108 |
+
buf = b''
|
| 109 |
+
tmp = tmp[i + len_delim:]
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
# ((opt, type), ... )
|
| 113 |
+
RE_OPTS = re.compile(r'\n {4}(\S+)\s{2,}:\s*([^,]+)')
|
| 114 |
+
# better split method assuming no positional args
|
| 115 |
+
RE_SHLEX = re.compile(r'\s*(?<!\S)--?([^\s=]+)(\s+|=|$)')
|
| 116 |
+
|
| 117 |
+
# TODO: add custom support for some of the following?
|
| 118 |
+
UNSUPPORTED_OPTS = ('iterable', 'gui', 'out', 'file')
|
| 119 |
+
|
| 120 |
+
# The 8 leading spaces are required for consistency
|
| 121 |
+
CLI_EXTRA_DOC = r"""
|
| 122 |
+
Extra CLI Options
|
| 123 |
+
-----------------
|
| 124 |
+
name : type, optional
|
| 125 |
+
TODO: find out why this is needed.
|
| 126 |
+
delim : chr, optional
|
| 127 |
+
Delimiting character [default: '\n']. Use '\0' for null.
|
| 128 |
+
N.B.: on Windows systems, Python converts '\n' to '\r\n'.
|
| 129 |
+
buf_size : int, optional
|
| 130 |
+
String buffer size in bytes [default: 256]
|
| 131 |
+
used when `delim` is specified.
|
| 132 |
+
bytes : bool, optional
|
| 133 |
+
If true, will count bytes, ignore `delim`, and default
|
| 134 |
+
`unit_scale` to True, `unit_divisor` to 1024, and `unit` to 'B'.
|
| 135 |
+
tee : bool, optional
|
| 136 |
+
If true, passes `stdin` to both `stderr` and `stdout`.
|
| 137 |
+
update : bool, optional
|
| 138 |
+
If true, will treat input as newly elapsed iterations,
|
| 139 |
+
i.e. numbers to pass to `update()`. Note that this is slow
|
| 140 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 141 |
+
update_to : bool, optional
|
| 142 |
+
If true, will treat input as total elapsed iterations,
|
| 143 |
+
i.e. numbers to assign to `self.n`. Note that this is slow
|
| 144 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 145 |
+
null : bool, optional
|
| 146 |
+
If true, will discard input (no stdout).
|
| 147 |
+
manpath : str, optional
|
| 148 |
+
Directory in which to install tqdm man pages.
|
| 149 |
+
comppath : str, optional
|
| 150 |
+
Directory in which to place tqdm completion.
|
| 151 |
+
log : str, optional
|
| 152 |
+
CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
|
| 153 |
+
"""
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def main(fp=sys.stderr, argv=None):
|
| 157 |
+
"""
|
| 158 |
+
Parameters (internal use only)
|
| 159 |
+
---------
|
| 160 |
+
fp : file-like object for tqdm
|
| 161 |
+
argv : list (default: sys.argv[1:])
|
| 162 |
+
"""
|
| 163 |
+
if argv is None:
|
| 164 |
+
argv = sys.argv[1:]
|
| 165 |
+
try:
|
| 166 |
+
log_idx = argv.index('--log')
|
| 167 |
+
except ValueError:
|
| 168 |
+
for i in argv:
|
| 169 |
+
if i.startswith('--log='):
|
| 170 |
+
logLevel = i[len('--log='):]
|
| 171 |
+
break
|
| 172 |
+
else:
|
| 173 |
+
logLevel = 'INFO'
|
| 174 |
+
else:
|
| 175 |
+
# argv.pop(log_idx)
|
| 176 |
+
# logLevel = argv.pop(log_idx)
|
| 177 |
+
logLevel = argv[log_idx + 1]
|
| 178 |
+
logging.basicConfig(level=getattr(logging, logLevel),
|
| 179 |
+
format="%(levelname)s:%(module)s:%(lineno)d:%(message)s")
|
| 180 |
+
|
| 181 |
+
# py<3.13 doesn't dedent docstrings
|
| 182 |
+
d = (tqdm.__doc__ if sys.version_info < (3, 13)
|
| 183 |
+
else indent(tqdm.__doc__, " ")) + CLI_EXTRA_DOC
|
| 184 |
+
|
| 185 |
+
opt_types = dict(RE_OPTS.findall(d))
|
| 186 |
+
# opt_types['delim'] = 'chr'
|
| 187 |
+
|
| 188 |
+
for o in UNSUPPORTED_OPTS:
|
| 189 |
+
opt_types.pop(o)
|
| 190 |
+
|
| 191 |
+
log.debug(sorted(opt_types.items()))
|
| 192 |
+
|
| 193 |
+
# d = RE_OPTS.sub(r' --\1=<\1> : \2', d)
|
| 194 |
+
split = RE_OPTS.split(d)
|
| 195 |
+
opt_types_desc = zip(split[1::3], split[2::3], split[3::3])
|
| 196 |
+
d = ''.join(('\n --{0} : {2}{3}' if otd[1] == 'bool' else
|
| 197 |
+
'\n --{0}=<{1}> : {2}{3}').format(
|
| 198 |
+
otd[0].replace('_', '-'), otd[0], *otd[1:])
|
| 199 |
+
for otd in opt_types_desc if otd[0] not in UNSUPPORTED_OPTS)
|
| 200 |
+
|
| 201 |
+
help_short = "Usage:\n tqdm [--help | options]\n"
|
| 202 |
+
d = help_short + """
|
| 203 |
+
Options:
|
| 204 |
+
-h, --help Print this help and exit.
|
| 205 |
+
-v, --version Print version and exit.
|
| 206 |
+
""" + d.strip('\n') + '\n'
|
| 207 |
+
|
| 208 |
+
# opts = docopt(d, version=__version__)
|
| 209 |
+
if any(v in argv for v in ('-v', '--version')):
|
| 210 |
+
sys.stdout.write(__version__ + '\n')
|
| 211 |
+
sys.exit(0)
|
| 212 |
+
elif any(v in argv for v in ('-h', '--help')):
|
| 213 |
+
sys.stdout.write(d + '\n')
|
| 214 |
+
sys.exit(0)
|
| 215 |
+
elif argv and argv[0][:2] != '--':
|
| 216 |
+
sys.stderr.write(f"Error:Unknown argument:{argv[0]}\n{help_short}")
|
| 217 |
+
|
| 218 |
+
argv = RE_SHLEX.split(' '.join(["tqdm"] + argv))
|
| 219 |
+
opts = dict(zip(argv[1::3], argv[3::3]))
|
| 220 |
+
|
| 221 |
+
log.debug(opts)
|
| 222 |
+
opts.pop('log', True)
|
| 223 |
+
|
| 224 |
+
tqdm_args = {'file': fp}
|
| 225 |
+
try:
|
| 226 |
+
for (o, v) in opts.items():
|
| 227 |
+
o = o.replace('-', '_')
|
| 228 |
+
try:
|
| 229 |
+
tqdm_args[o] = cast(v, opt_types[o])
|
| 230 |
+
except KeyError as e:
|
| 231 |
+
raise TqdmKeyError(str(e))
|
| 232 |
+
log.debug('args:' + str(tqdm_args))
|
| 233 |
+
|
| 234 |
+
delim_per_char = tqdm_args.pop('bytes', False)
|
| 235 |
+
update = tqdm_args.pop('update', False)
|
| 236 |
+
update_to = tqdm_args.pop('update_to', False)
|
| 237 |
+
if sum((delim_per_char, update, update_to)) > 1:
|
| 238 |
+
raise TqdmKeyError("Can only have one of --bytes --update --update_to")
|
| 239 |
+
except Exception:
|
| 240 |
+
fp.write("\nError:\n" + help_short)
|
| 241 |
+
stdin, stdout_write = sys.stdin, sys.stdout.write
|
| 242 |
+
for i in stdin:
|
| 243 |
+
stdout_write(i)
|
| 244 |
+
raise
|
| 245 |
+
else:
|
| 246 |
+
buf_size = tqdm_args.pop('buf_size', 256)
|
| 247 |
+
delim = tqdm_args.pop('delim', b'\\n')
|
| 248 |
+
tee = tqdm_args.pop('tee', False)
|
| 249 |
+
manpath = tqdm_args.pop('manpath', None)
|
| 250 |
+
comppath = tqdm_args.pop('comppath', None)
|
| 251 |
+
if tqdm_args.pop('null', False):
|
| 252 |
+
class stdout:
|
| 253 |
+
@staticmethod
|
| 254 |
+
def write(_):
|
| 255 |
+
pass
|
| 256 |
+
else:
|
| 257 |
+
stdout = sys.stdout
|
| 258 |
+
stdout = getattr(stdout, 'buffer', stdout)
|
| 259 |
+
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
|
| 260 |
+
if manpath or comppath:
|
| 261 |
+
try: # py<3.9
|
| 262 |
+
import importlib_resources as resources
|
| 263 |
+
except ImportError:
|
| 264 |
+
from importlib import resources
|
| 265 |
+
from pathlib import Path
|
| 266 |
+
|
| 267 |
+
def cp(name, dst):
|
| 268 |
+
"""copy resource `name` to `dst`"""
|
| 269 |
+
fi = resources.files('tqdm') / name
|
| 270 |
+
dst.write_bytes(fi.read_bytes())
|
| 271 |
+
log.info("written:%s", dst)
|
| 272 |
+
if manpath is not None:
|
| 273 |
+
cp('tqdm.1', Path(manpath) / 'tqdm.1')
|
| 274 |
+
if comppath is not None:
|
| 275 |
+
cp('completion.sh', Path(comppath) / 'tqdm_completion.sh')
|
| 276 |
+
sys.exit(0)
|
| 277 |
+
if tee:
|
| 278 |
+
stdout_write = stdout.write
|
| 279 |
+
fp_write = getattr(fp, 'buffer', fp).write
|
| 280 |
+
|
| 281 |
+
class stdout: # pylint: disable=function-redefined
|
| 282 |
+
@staticmethod
|
| 283 |
+
def write(x):
|
| 284 |
+
with tqdm.external_write_mode(file=fp):
|
| 285 |
+
fp_write(x)
|
| 286 |
+
stdout_write(x)
|
| 287 |
+
if delim_per_char:
|
| 288 |
+
tqdm_args.setdefault('unit', 'B')
|
| 289 |
+
tqdm_args.setdefault('unit_scale', True)
|
| 290 |
+
tqdm_args.setdefault('unit_divisor', 1024)
|
| 291 |
+
log.debug(tqdm_args)
|
| 292 |
+
with tqdm(**tqdm_args) as t:
|
| 293 |
+
posix_pipe(stdin, stdout, '', buf_size, t.update)
|
| 294 |
+
elif delim == b'\\n':
|
| 295 |
+
log.debug(tqdm_args)
|
| 296 |
+
write = stdout.write
|
| 297 |
+
if update or update_to:
|
| 298 |
+
with tqdm(**tqdm_args) as t:
|
| 299 |
+
if update:
|
| 300 |
+
def callback(i):
|
| 301 |
+
t.update(numeric(i.decode()))
|
| 302 |
+
else: # update_to
|
| 303 |
+
def callback(i):
|
| 304 |
+
t.update(numeric(i.decode()) - t.n)
|
| 305 |
+
for i in stdin:
|
| 306 |
+
write(i)
|
| 307 |
+
callback(i)
|
| 308 |
+
else:
|
| 309 |
+
for i in tqdm(stdin, **tqdm_args):
|
| 310 |
+
write(i)
|
| 311 |
+
else:
|
| 312 |
+
log.debug(tqdm_args)
|
| 313 |
+
with tqdm(**tqdm_args) as t:
|
| 314 |
+
callback_len = False
|
| 315 |
+
if update:
|
| 316 |
+
def callback(i):
|
| 317 |
+
t.update(numeric(i.decode()))
|
| 318 |
+
elif update_to:
|
| 319 |
+
def callback(i):
|
| 320 |
+
t.update(numeric(i.decode()) - t.n)
|
| 321 |
+
else:
|
| 322 |
+
callback = t.update
|
| 323 |
+
callback_len = True
|
| 324 |
+
posix_pipe(stdin, stdout, delim, buf_size, callback, callback_len)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/completion.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
_tqdm(){
|
| 3 |
+
local cur prv
|
| 4 |
+
cur="${COMP_WORDS[COMP_CWORD]}"
|
| 5 |
+
prv="${COMP_WORDS[COMP_CWORD - 1]}"
|
| 6 |
+
|
| 7 |
+
case ${prv} in
|
| 8 |
+
--bar_format|--buf_size|--colour|--comppath|--delay|--delim|--desc|--initial|--lock_args|--manpath|--maxinterval|--mininterval|--miniters|--ncols|--nrows|--position|--postfix|--smoothing|--total|--unit|--unit_divisor)
|
| 9 |
+
# await user input
|
| 10 |
+
;;
|
| 11 |
+
"--log")
|
| 12 |
+
COMPREPLY=($(compgen -W 'CRITICAL FATAL ERROR WARN WARNING INFO DEBUG NOTSET' -- ${cur}))
|
| 13 |
+
;;
|
| 14 |
+
*)
|
| 15 |
+
COMPREPLY=($(compgen -W '--ascii --bar_format --buf_size --bytes --colour --comppath --delay --delim --desc --disable --dynamic_ncols --help --initial --leave --lock_args --log --manpath --maxinterval --mininterval --miniters --ncols --nrows --null --position --postfix --smoothing --tee --total --unit --unit_divisor --unit_scale --update --update_to --version --write_bytes -h -v' -- ${cur}))
|
| 16 |
+
;;
|
| 17 |
+
esac
|
| 18 |
+
}
|
| 19 |
+
complete -F _tqdm tqdm
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/__init__.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Thin wrappers around common functions.
|
| 3 |
+
|
| 4 |
+
Subpackages contain potentially unstable extensions.
|
| 5 |
+
"""
|
| 6 |
+
from warnings import warn
|
| 7 |
+
|
| 8 |
+
from ..auto import tqdm as tqdm_auto
|
| 9 |
+
from ..std import TqdmDeprecationWarning, tqdm
|
| 10 |
+
from ..utils import ObjectWrapper
|
| 11 |
+
|
| 12 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 13 |
+
__all__ = ['tenumerate', 'tzip', 'tmap']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class DummyTqdmFile(ObjectWrapper):
|
| 17 |
+
"""Dummy file-like that will write to tqdm"""
|
| 18 |
+
|
| 19 |
+
def __init__(self, wrapped):
|
| 20 |
+
super().__init__(wrapped)
|
| 21 |
+
self._buf = []
|
| 22 |
+
|
| 23 |
+
def write(self, x, nolock=False):
|
| 24 |
+
nl = b"\n" if isinstance(x, bytes) else "\n"
|
| 25 |
+
pre, sep, post = x.rpartition(nl)
|
| 26 |
+
if sep:
|
| 27 |
+
blank = type(nl)()
|
| 28 |
+
tqdm.write(blank.join(self._buf + [pre, sep]),
|
| 29 |
+
end=blank, file=self._wrapped, nolock=nolock)
|
| 30 |
+
self._buf = [post]
|
| 31 |
+
else:
|
| 32 |
+
self._buf.append(x)
|
| 33 |
+
|
| 34 |
+
def __del__(self):
|
| 35 |
+
if self._buf:
|
| 36 |
+
blank = type(self._buf[0])()
|
| 37 |
+
try:
|
| 38 |
+
tqdm.write(blank.join(self._buf), end=blank, file=self._wrapped)
|
| 39 |
+
except (OSError, ValueError):
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def builtin_iterable(func):
|
| 44 |
+
"""Returns `func`"""
|
| 45 |
+
warn("This function has no effect, and will be removed in tqdm==5.0.0",
|
| 46 |
+
TqdmDeprecationWarning, stacklevel=2)
|
| 47 |
+
return func
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def tenumerate(iterable, start=0, total=None, tqdm_class=tqdm_auto, **tqdm_kwargs):
|
| 51 |
+
"""
|
| 52 |
+
Equivalent of `numpy.ndenumerate` or builtin `enumerate`.
|
| 53 |
+
|
| 54 |
+
Parameters
|
| 55 |
+
----------
|
| 56 |
+
tqdm_class : [default: tqdm.auto.tqdm].
|
| 57 |
+
"""
|
| 58 |
+
try:
|
| 59 |
+
import numpy as np
|
| 60 |
+
except ImportError:
|
| 61 |
+
pass
|
| 62 |
+
else:
|
| 63 |
+
if isinstance(iterable, np.ndarray):
|
| 64 |
+
return tqdm_class(np.ndenumerate(iterable), total=total or iterable.size,
|
| 65 |
+
**tqdm_kwargs)
|
| 66 |
+
return enumerate(tqdm_class(iterable, total=total, **tqdm_kwargs), start)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def tzip(iter1, *iter2plus, **tqdm_kwargs):
|
| 70 |
+
"""
|
| 71 |
+
Equivalent of builtin `zip`.
|
| 72 |
+
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
tqdm_class : [default: tqdm.auto.tqdm].
|
| 76 |
+
"""
|
| 77 |
+
kwargs = tqdm_kwargs.copy()
|
| 78 |
+
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
|
| 79 |
+
yield from zip(tqdm_class(iter1, **kwargs), *iter2plus)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def tmap(function, *sequences, **tqdm_kwargs):
|
| 83 |
+
"""
|
| 84 |
+
Equivalent of builtin `map`.
|
| 85 |
+
|
| 86 |
+
Parameters
|
| 87 |
+
----------
|
| 88 |
+
tqdm_class : [default: tqdm.auto.tqdm].
|
| 89 |
+
"""
|
| 90 |
+
for i in tzip(*sequences, **tqdm_kwargs):
|
| 91 |
+
yield function(*i)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/bells.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Even more features than `tqdm.auto` (all the bells & whistles):
|
| 3 |
+
|
| 4 |
+
- `tqdm.auto`
|
| 5 |
+
- `tqdm.tqdm.pandas`
|
| 6 |
+
- `tqdm.contrib.telegram`
|
| 7 |
+
+ uses `${TQDM_TELEGRAM_TOKEN}` and `${TQDM_TELEGRAM_CHAT_ID}`
|
| 8 |
+
- `tqdm.contrib.discord`
|
| 9 |
+
+ uses `${TQDM_DISCORD_TOKEN}` and `${TQDM_DISCORD_CHANNEL_ID}`
|
| 10 |
+
"""
|
| 11 |
+
__all__ = ['tqdm', 'trange']
|
| 12 |
+
import warnings
|
| 13 |
+
from os import getenv
|
| 14 |
+
|
| 15 |
+
if getenv("TQDM_SLACK_TOKEN") and getenv("TQDM_SLACK_CHANNEL"):
|
| 16 |
+
from .slack import tqdm, trange
|
| 17 |
+
elif getenv("TQDM_TELEGRAM_TOKEN") and getenv("TQDM_TELEGRAM_CHAT_ID"):
|
| 18 |
+
from .telegram import tqdm, trange
|
| 19 |
+
elif getenv("TQDM_DISCORD_TOKEN") and getenv("TQDM_DISCORD_CHANNEL_ID"):
|
| 20 |
+
from .discord import tqdm, trange
|
| 21 |
+
else:
|
| 22 |
+
from ..auto import tqdm, trange
|
| 23 |
+
|
| 24 |
+
with warnings.catch_warnings():
|
| 25 |
+
warnings.simplefilter("ignore", category=FutureWarning)
|
| 26 |
+
tqdm.pandas()
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/concurrent.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Thin wrappers around `concurrent.futures`.
|
| 3 |
+
"""
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
from operator import length_hint
|
| 6 |
+
from os import cpu_count
|
| 7 |
+
|
| 8 |
+
from ..auto import tqdm as tqdm_auto
|
| 9 |
+
from ..std import TqdmWarning
|
| 10 |
+
|
| 11 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 12 |
+
__all__ = ['thread_map', 'process_map']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@contextmanager
|
| 16 |
+
def ensure_lock(tqdm_class, lock_name=""):
|
| 17 |
+
"""get (create if necessary) and then restore `tqdm_class`'s lock"""
|
| 18 |
+
old_lock = getattr(tqdm_class, '_lock', None) # don't create a new lock
|
| 19 |
+
lock = old_lock or tqdm_class.get_lock() # maybe create a new lock
|
| 20 |
+
lock = getattr(lock, lock_name, lock) # maybe subtype
|
| 21 |
+
tqdm_class.set_lock(lock)
|
| 22 |
+
yield lock
|
| 23 |
+
if old_lock is None:
|
| 24 |
+
del tqdm_class._lock
|
| 25 |
+
else:
|
| 26 |
+
tqdm_class.set_lock(old_lock)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs):
|
| 30 |
+
"""
|
| 31 |
+
Implementation of `thread_map` and `process_map`.
|
| 32 |
+
|
| 33 |
+
Parameters
|
| 34 |
+
----------
|
| 35 |
+
tqdm_class : [default: tqdm.auto.tqdm].
|
| 36 |
+
max_workers : [default: min(32, cpu_count() + 4)].
|
| 37 |
+
chunksize : [default: 1].
|
| 38 |
+
lock_name : [default: "":str].
|
| 39 |
+
"""
|
| 40 |
+
kwargs = tqdm_kwargs.copy()
|
| 41 |
+
if "total" not in kwargs:
|
| 42 |
+
kwargs["total"] = length_hint(iterables[0])
|
| 43 |
+
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
|
| 44 |
+
max_workers = kwargs.pop("max_workers", min(32, cpu_count() + 4))
|
| 45 |
+
chunksize = kwargs.pop("chunksize", 1)
|
| 46 |
+
lock_name = kwargs.pop("lock_name", "")
|
| 47 |
+
with ensure_lock(tqdm_class, lock_name=lock_name) as lk:
|
| 48 |
+
# share lock in case workers are already using `tqdm`
|
| 49 |
+
with PoolExecutor(max_workers=max_workers, initializer=tqdm_class.set_lock,
|
| 50 |
+
initargs=(lk,)) as ex:
|
| 51 |
+
return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def thread_map(fn, *iterables, **tqdm_kwargs):
|
| 55 |
+
"""
|
| 56 |
+
Equivalent of `list(map(fn, *iterables))`
|
| 57 |
+
driven by `concurrent.futures.ThreadPoolExecutor`.
|
| 58 |
+
|
| 59 |
+
Parameters
|
| 60 |
+
----------
|
| 61 |
+
tqdm_class : optional
|
| 62 |
+
`tqdm` class to use for bars [default: tqdm.auto.tqdm].
|
| 63 |
+
max_workers : int, optional
|
| 64 |
+
Maximum number of workers to spawn; passed to
|
| 65 |
+
`concurrent.futures.ThreadPoolExecutor.__init__`.
|
| 66 |
+
[default: max(32, cpu_count() + 4)].
|
| 67 |
+
"""
|
| 68 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 69 |
+
return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def process_map(fn, *iterables, **tqdm_kwargs):
|
| 73 |
+
"""
|
| 74 |
+
Equivalent of `list(map(fn, *iterables))`
|
| 75 |
+
driven by `concurrent.futures.ProcessPoolExecutor`.
|
| 76 |
+
|
| 77 |
+
Parameters
|
| 78 |
+
----------
|
| 79 |
+
tqdm_class : optional
|
| 80 |
+
`tqdm` class to use for bars [default: tqdm.auto.tqdm].
|
| 81 |
+
max_workers : int, optional
|
| 82 |
+
Maximum number of workers to spawn; passed to
|
| 83 |
+
`concurrent.futures.ProcessPoolExecutor.__init__`.
|
| 84 |
+
[default: min(32, cpu_count() + 4)].
|
| 85 |
+
chunksize : int, optional
|
| 86 |
+
Size of chunks sent to worker processes; passed to
|
| 87 |
+
`concurrent.futures.ProcessPoolExecutor.map`. [default: 1].
|
| 88 |
+
lock_name : str, optional
|
| 89 |
+
Member of `tqdm_class.get_lock()` to use [default: mp_lock].
|
| 90 |
+
"""
|
| 91 |
+
from concurrent.futures import ProcessPoolExecutor
|
| 92 |
+
if iterables and "chunksize" not in tqdm_kwargs:
|
| 93 |
+
# default `chunksize=1` has poor performance for large iterables
|
| 94 |
+
# (most time spent dispatching items to workers).
|
| 95 |
+
longest_iterable_len = max(map(length_hint, iterables))
|
| 96 |
+
if longest_iterable_len > 1000:
|
| 97 |
+
from warnings import warn
|
| 98 |
+
warn("Iterable length %d > 1000 but `chunksize` is not set."
|
| 99 |
+
" This may seriously degrade multiprocess performance."
|
| 100 |
+
" Set `chunksize=1` or more." % longest_iterable_len,
|
| 101 |
+
TqdmWarning, stacklevel=2)
|
| 102 |
+
if "lock_name" not in tqdm_kwargs:
|
| 103 |
+
tqdm_kwargs = tqdm_kwargs.copy()
|
| 104 |
+
tqdm_kwargs["lock_name"] = "mp_lock"
|
| 105 |
+
return _executor_map(ProcessPoolExecutor, fn, *iterables, **tqdm_kwargs)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/discord.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sends updates to a Discord bot.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.contrib.discord import tqdm, trange
|
| 6 |
+
>>> for i in trange(10, token='{token}', channel_id='{channel_id}'):
|
| 7 |
+
... ...
|
| 8 |
+
|
| 9 |
+

|
| 10 |
+
"""
|
| 11 |
+
from os import getenv
|
| 12 |
+
from warnings import warn
|
| 13 |
+
|
| 14 |
+
from requests import Session
|
| 15 |
+
from requests.utils import default_user_agent
|
| 16 |
+
|
| 17 |
+
from ..auto import tqdm as tqdm_auto
|
| 18 |
+
from ..std import TqdmWarning
|
| 19 |
+
from ..version import __version__
|
| 20 |
+
from .utils_worker import MonoWorker
|
| 21 |
+
|
| 22 |
+
__author__ = {"github.com/": ["casperdcl", "guigoruiz1"]}
|
| 23 |
+
__all__ = ['DiscordIO', 'tqdm_discord', 'tdrange', 'tqdm', 'trange']
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class DiscordIO(MonoWorker):
|
| 27 |
+
"""Non-blocking file-like IO using a Discord Bot."""
|
| 28 |
+
API = "https://discord.com/api/v10"
|
| 29 |
+
UA = f"tqdm (https://tqdm.github.io, {__version__}) {default_user_agent()}"
|
| 30 |
+
|
| 31 |
+
def __init__(self, token, channel_id):
|
| 32 |
+
"""Creates a new message in the given `channel_id`."""
|
| 33 |
+
super().__init__()
|
| 34 |
+
self.token = token
|
| 35 |
+
self.channel_id = channel_id
|
| 36 |
+
self.session = Session()
|
| 37 |
+
self.text = self.__class__.__name__
|
| 38 |
+
self.message_id
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def message_id(self):
|
| 42 |
+
if hasattr(self, '_message_id'):
|
| 43 |
+
return self._message_id
|
| 44 |
+
try:
|
| 45 |
+
res = self.session.post(
|
| 46 |
+
f'{self.API}/channels/{self.channel_id}/messages',
|
| 47 |
+
headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA},
|
| 48 |
+
json={'content': f"`{self.text}`"}).json()
|
| 49 |
+
except Exception as e:
|
| 50 |
+
tqdm_auto.write(str(e))
|
| 51 |
+
else:
|
| 52 |
+
if res.get('error_code') == 429:
|
| 53 |
+
warn("Creation rate limit: try increasing `mininterval`.",
|
| 54 |
+
TqdmWarning, stacklevel=2)
|
| 55 |
+
else:
|
| 56 |
+
self._message_id = res['id']
|
| 57 |
+
return self._message_id
|
| 58 |
+
|
| 59 |
+
def write(self, s):
|
| 60 |
+
"""Replaces internal `message_id`'s text with `s`."""
|
| 61 |
+
if not s:
|
| 62 |
+
s = "..."
|
| 63 |
+
s = s.replace('\r', '').strip()
|
| 64 |
+
if s == self.text:
|
| 65 |
+
return # avoid duplicate message Bot error
|
| 66 |
+
message_id = self.message_id
|
| 67 |
+
if message_id is None:
|
| 68 |
+
return
|
| 69 |
+
self.text = s
|
| 70 |
+
try:
|
| 71 |
+
future = self.submit(
|
| 72 |
+
self.session.patch,
|
| 73 |
+
f'{self.API}/channels/{self.channel_id}/messages/{message_id}',
|
| 74 |
+
headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA},
|
| 75 |
+
json={'content': f"`{self.text}`"})
|
| 76 |
+
except Exception as e:
|
| 77 |
+
tqdm_auto.write(str(e))
|
| 78 |
+
else:
|
| 79 |
+
return future
|
| 80 |
+
|
| 81 |
+
def delete(self):
|
| 82 |
+
"""Deletes internal `message_id`."""
|
| 83 |
+
try:
|
| 84 |
+
future = self.submit(
|
| 85 |
+
self.session.delete,
|
| 86 |
+
f'{self.API}/channels/{self.channel_id}/messages/{self.message_id}',
|
| 87 |
+
headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA})
|
| 88 |
+
except Exception as e:
|
| 89 |
+
tqdm_auto.write(str(e))
|
| 90 |
+
else:
|
| 91 |
+
return future
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class tqdm_discord(tqdm_auto):
|
| 95 |
+
"""
|
| 96 |
+
Standard `tqdm.auto.tqdm` but also sends updates to a Discord Bot.
|
| 97 |
+
May take a few seconds to create (`__init__`).
|
| 98 |
+
|
| 99 |
+
- create a discord bot (not public, no requirement of OAuth2 code
|
| 100 |
+
grant, only send message permissions) & invite it to a channel:
|
| 101 |
+
<https://discordpy.readthedocs.io/en/latest/discord.html>
|
| 102 |
+
- copy the bot `{token}` & `{channel_id}` and paste below
|
| 103 |
+
|
| 104 |
+
>>> from tqdm.contrib.discord import tqdm, trange
|
| 105 |
+
>>> for i in tqdm(iterable, token='{token}', channel_id='{channel_id}'):
|
| 106 |
+
... ...
|
| 107 |
+
"""
|
| 108 |
+
def __init__(self, *args, **kwargs):
|
| 109 |
+
"""
|
| 110 |
+
Parameters
|
| 111 |
+
----------
|
| 112 |
+
token : str, required. Discord bot token
|
| 113 |
+
[default: ${TQDM_DISCORD_TOKEN}].
|
| 114 |
+
channel_id : int, required. Discord channel ID
|
| 115 |
+
[default: ${TQDM_DISCORD_CHANNEL_ID}].
|
| 116 |
+
|
| 117 |
+
See `tqdm.auto.tqdm.__init__` for other parameters.
|
| 118 |
+
"""
|
| 119 |
+
if not kwargs.get('disable'):
|
| 120 |
+
kwargs = kwargs.copy()
|
| 121 |
+
self.dio = DiscordIO(
|
| 122 |
+
kwargs.pop('token', getenv('TQDM_DISCORD_TOKEN')),
|
| 123 |
+
kwargs.pop('channel_id', getenv('TQDM_DISCORD_CHANNEL_ID')))
|
| 124 |
+
super().__init__(*args, **kwargs)
|
| 125 |
+
|
| 126 |
+
def display(self, **kwargs):
|
| 127 |
+
super().display(**kwargs)
|
| 128 |
+
fmt = self.format_dict
|
| 129 |
+
if fmt.get('bar_format', None):
|
| 130 |
+
fmt['bar_format'] = fmt['bar_format'].replace(
|
| 131 |
+
'<bar/>', '{bar:10u}').replace('{bar}', '{bar:10u}')
|
| 132 |
+
else:
|
| 133 |
+
fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
|
| 134 |
+
self.dio.write(self.format_meter(**fmt))
|
| 135 |
+
|
| 136 |
+
def clear(self, *args, **kwargs):
|
| 137 |
+
super().clear(*args, **kwargs)
|
| 138 |
+
if not self.disable:
|
| 139 |
+
self.dio.write("")
|
| 140 |
+
|
| 141 |
+
def close(self):
|
| 142 |
+
if self.disable:
|
| 143 |
+
return
|
| 144 |
+
super().close()
|
| 145 |
+
if not (self.leave or (self.leave is None and self.pos == 0)):
|
| 146 |
+
self.dio.delete()
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def tdrange(*args, **kwargs):
|
| 150 |
+
"""Shortcut for `tqdm.contrib.discord.tqdm(range(*args), **kwargs)`."""
|
| 151 |
+
return tqdm_discord(range(*args), **kwargs)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
# Aliases
|
| 155 |
+
tqdm = tqdm_discord
|
| 156 |
+
trange = tdrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/itertools.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Thin wrappers around `itertools`.
|
| 3 |
+
"""
|
| 4 |
+
import itertools
|
| 5 |
+
|
| 6 |
+
from ..auto import tqdm as tqdm_auto
|
| 7 |
+
|
| 8 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 9 |
+
__all__ = ['product']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def product(*iterables, **tqdm_kwargs):
|
| 13 |
+
"""
|
| 14 |
+
Equivalent of `itertools.product`.
|
| 15 |
+
|
| 16 |
+
Parameters
|
| 17 |
+
----------
|
| 18 |
+
tqdm_class : [default: tqdm.auto.tqdm].
|
| 19 |
+
"""
|
| 20 |
+
kwargs = tqdm_kwargs.copy()
|
| 21 |
+
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
|
| 22 |
+
try:
|
| 23 |
+
lens = list(map(len, iterables))
|
| 24 |
+
except TypeError:
|
| 25 |
+
total = None
|
| 26 |
+
else:
|
| 27 |
+
total = 1
|
| 28 |
+
for i in lens:
|
| 29 |
+
total *= i
|
| 30 |
+
kwargs.setdefault("total", total)
|
| 31 |
+
with tqdm_class(**kwargs) as t:
|
| 32 |
+
it = itertools.product(*iterables)
|
| 33 |
+
for i in it:
|
| 34 |
+
yield i
|
| 35 |
+
t.update()
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/logging.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Helper functionality for interoperability with stdlib `logging`.
|
| 3 |
+
"""
|
| 4 |
+
import logging
|
| 5 |
+
import sys
|
| 6 |
+
from contextlib import contextmanager
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
from typing import Iterator, List, Optional, Type # noqa: F401
|
| 10 |
+
except ImportError:
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
from ..std import tqdm as std_tqdm
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class _TqdmLoggingHandler(logging.StreamHandler):
|
| 17 |
+
def __init__(
|
| 18 |
+
self,
|
| 19 |
+
tqdm_class=std_tqdm # type: Type[std_tqdm]
|
| 20 |
+
):
|
| 21 |
+
super().__init__()
|
| 22 |
+
self.tqdm_class = tqdm_class
|
| 23 |
+
|
| 24 |
+
def emit(self, record):
|
| 25 |
+
try:
|
| 26 |
+
msg = self.format(record)
|
| 27 |
+
self.tqdm_class.write(msg, file=self.stream)
|
| 28 |
+
self.flush()
|
| 29 |
+
except (KeyboardInterrupt, SystemExit):
|
| 30 |
+
raise
|
| 31 |
+
except: # noqa pylint: disable=bare-except
|
| 32 |
+
self.handleError(record)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _is_console_logging_handler(handler):
|
| 36 |
+
return (isinstance(handler, logging.StreamHandler)
|
| 37 |
+
and handler.stream in {sys.stdout, sys.stderr})
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _get_first_found_console_logging_handler(handlers):
|
| 41 |
+
for handler in handlers:
|
| 42 |
+
if _is_console_logging_handler(handler):
|
| 43 |
+
return handler
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@contextmanager
|
| 47 |
+
def logging_redirect_tqdm(
|
| 48 |
+
loggers=None, # type: Optional[List[logging.Logger]],
|
| 49 |
+
tqdm_class=std_tqdm # type: Type[std_tqdm]
|
| 50 |
+
):
|
| 51 |
+
# type: (...) -> Iterator[None]
|
| 52 |
+
"""
|
| 53 |
+
Context manager redirecting console logging to `tqdm.write()`, leaving
|
| 54 |
+
other logging handlers (e.g. log files) unaffected.
|
| 55 |
+
|
| 56 |
+
Parameters
|
| 57 |
+
----------
|
| 58 |
+
loggers : list, optional
|
| 59 |
+
Which handlers to redirect (default: [logging.root]).
|
| 60 |
+
tqdm_class : optional
|
| 61 |
+
|
| 62 |
+
Example
|
| 63 |
+
-------
|
| 64 |
+
```python
|
| 65 |
+
import logging
|
| 66 |
+
from tqdm import trange
|
| 67 |
+
from tqdm.contrib.logging import logging_redirect_tqdm
|
| 68 |
+
|
| 69 |
+
LOG = logging.getLogger(__name__)
|
| 70 |
+
|
| 71 |
+
if __name__ == '__main__':
|
| 72 |
+
logging.basicConfig(level=logging.INFO)
|
| 73 |
+
with logging_redirect_tqdm():
|
| 74 |
+
for i in trange(9):
|
| 75 |
+
if i == 4:
|
| 76 |
+
LOG.info("console logging redirected to `tqdm.write()`")
|
| 77 |
+
# logging restored
|
| 78 |
+
```
|
| 79 |
+
"""
|
| 80 |
+
if loggers is None:
|
| 81 |
+
loggers = [logging.root]
|
| 82 |
+
original_handlers_list = [logger.handlers for logger in loggers]
|
| 83 |
+
try:
|
| 84 |
+
for logger in loggers:
|
| 85 |
+
tqdm_handler = _TqdmLoggingHandler(tqdm_class)
|
| 86 |
+
orig_handler = _get_first_found_console_logging_handler(logger.handlers)
|
| 87 |
+
if orig_handler is not None:
|
| 88 |
+
tqdm_handler.setFormatter(orig_handler.formatter)
|
| 89 |
+
tqdm_handler.stream = orig_handler.stream
|
| 90 |
+
logger.handlers = [
|
| 91 |
+
handler for handler in logger.handlers
|
| 92 |
+
if not _is_console_logging_handler(handler)] + [tqdm_handler]
|
| 93 |
+
yield
|
| 94 |
+
finally:
|
| 95 |
+
for logger, original_handlers in zip(loggers, original_handlers_list):
|
| 96 |
+
logger.handlers = original_handlers
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
@contextmanager
|
| 100 |
+
def tqdm_logging_redirect(
|
| 101 |
+
*args,
|
| 102 |
+
# loggers=None, # type: Optional[List[logging.Logger]]
|
| 103 |
+
# tqdm=None, # type: Optional[Type[tqdm.tqdm]]
|
| 104 |
+
**kwargs
|
| 105 |
+
):
|
| 106 |
+
# type: (...) -> Iterator[None]
|
| 107 |
+
"""
|
| 108 |
+
Convenience shortcut for:
|
| 109 |
+
```python
|
| 110 |
+
with tqdm_class(*args, **tqdm_kwargs) as pbar:
|
| 111 |
+
with logging_redirect_tqdm(loggers=loggers, tqdm_class=tqdm_class):
|
| 112 |
+
yield pbar
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
Parameters
|
| 116 |
+
----------
|
| 117 |
+
tqdm_class : optional, (default: tqdm.std.tqdm).
|
| 118 |
+
loggers : optional, list.
|
| 119 |
+
**tqdm_kwargs : passed to `tqdm_class`.
|
| 120 |
+
"""
|
| 121 |
+
tqdm_kwargs = kwargs.copy()
|
| 122 |
+
loggers = tqdm_kwargs.pop('loggers', None)
|
| 123 |
+
tqdm_class = tqdm_kwargs.pop('tqdm_class', std_tqdm)
|
| 124 |
+
with tqdm_class(*args, **tqdm_kwargs) as pbar:
|
| 125 |
+
with logging_redirect_tqdm(loggers=loggers, tqdm_class=tqdm_class):
|
| 126 |
+
yield pbar
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/slack.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sends updates to a Slack app.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.contrib.slack import tqdm, trange
|
| 6 |
+
>>> for i in trange(10, token='{token}', channel='{channel}'):
|
| 7 |
+
... ...
|
| 8 |
+
|
| 9 |
+

|
| 10 |
+
"""
|
| 11 |
+
import logging
|
| 12 |
+
from os import getenv
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
from slack_sdk import WebClient
|
| 16 |
+
except ImportError:
|
| 17 |
+
raise ImportError("Please `pip install slack-sdk`")
|
| 18 |
+
|
| 19 |
+
from ..auto import tqdm as tqdm_auto
|
| 20 |
+
from .utils_worker import MonoWorker
|
| 21 |
+
|
| 22 |
+
__author__ = {"github.com/": ["0x2b3bfa0", "casperdcl"]}
|
| 23 |
+
__all__ = ['SlackIO', 'tqdm_slack', 'tsrange', 'tqdm', 'trange']
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class SlackIO(MonoWorker):
|
| 27 |
+
"""Non-blocking file-like IO using a Slack app."""
|
| 28 |
+
def __init__(self, token, channel):
|
| 29 |
+
"""Creates a new message in the given `channel`."""
|
| 30 |
+
super().__init__()
|
| 31 |
+
self.client = WebClient(token=token)
|
| 32 |
+
self.text = self.__class__.__name__
|
| 33 |
+
try:
|
| 34 |
+
self.message = self.client.chat_postMessage(channel=channel, text=self.text)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
tqdm_auto.write(str(e))
|
| 37 |
+
self.message = None
|
| 38 |
+
|
| 39 |
+
def write(self, s):
|
| 40 |
+
"""Replaces internal `message`'s text with `s`."""
|
| 41 |
+
if not s:
|
| 42 |
+
s = "..."
|
| 43 |
+
s = s.replace('\r', '').strip()
|
| 44 |
+
if s == self.text:
|
| 45 |
+
return # skip duplicate message
|
| 46 |
+
message = self.message
|
| 47 |
+
if message is None:
|
| 48 |
+
return
|
| 49 |
+
self.text = s
|
| 50 |
+
try:
|
| 51 |
+
future = self.submit(self.client.chat_update, channel=message['channel'],
|
| 52 |
+
ts=message['ts'], text='`' + s + '`')
|
| 53 |
+
except Exception as e:
|
| 54 |
+
tqdm_auto.write(str(e))
|
| 55 |
+
else:
|
| 56 |
+
return future
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class tqdm_slack(tqdm_auto):
|
| 60 |
+
"""
|
| 61 |
+
Standard `tqdm.auto.tqdm` but also sends updates to a Slack app.
|
| 62 |
+
May take a few seconds to create (`__init__`).
|
| 63 |
+
|
| 64 |
+
- create a Slack app with the `chat:write` scope & invite it to a
|
| 65 |
+
channel: <https://api.slack.com/authentication/basics>
|
| 66 |
+
- copy the bot `{token}` & `{channel}` and paste below
|
| 67 |
+
>>> from tqdm.contrib.slack import tqdm, trange
|
| 68 |
+
>>> for i in tqdm(iterable, token='{token}', channel='{channel}'):
|
| 69 |
+
... ...
|
| 70 |
+
"""
|
| 71 |
+
def __init__(self, *args, **kwargs):
|
| 72 |
+
"""
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
token : str, required. Slack token
|
| 76 |
+
[default: ${TQDM_SLACK_TOKEN}].
|
| 77 |
+
channel : int, required. Slack channel
|
| 78 |
+
[default: ${TQDM_SLACK_CHANNEL}].
|
| 79 |
+
mininterval : float, optional.
|
| 80 |
+
Minimum of [default: 1.5] to avoid rate limit.
|
| 81 |
+
|
| 82 |
+
See `tqdm.auto.tqdm.__init__` for other parameters.
|
| 83 |
+
"""
|
| 84 |
+
if not kwargs.get('disable'):
|
| 85 |
+
kwargs = kwargs.copy()
|
| 86 |
+
logging.getLogger("HTTPClient").setLevel(logging.WARNING)
|
| 87 |
+
self.sio = SlackIO(
|
| 88 |
+
kwargs.pop('token', getenv("TQDM_SLACK_TOKEN")),
|
| 89 |
+
kwargs.pop('channel', getenv("TQDM_SLACK_CHANNEL")))
|
| 90 |
+
kwargs['mininterval'] = max(1.5, kwargs.get('mininterval', 1.5))
|
| 91 |
+
super().__init__(*args, **kwargs)
|
| 92 |
+
|
| 93 |
+
def display(self, **kwargs):
|
| 94 |
+
super().display(**kwargs)
|
| 95 |
+
fmt = self.format_dict
|
| 96 |
+
if fmt.get('bar_format', None):
|
| 97 |
+
fmt['bar_format'] = fmt['bar_format'].replace(
|
| 98 |
+
'<bar/>', '`{bar:10}`').replace('{bar}', '`{bar:10u}`')
|
| 99 |
+
else:
|
| 100 |
+
fmt['bar_format'] = '{l_bar}`{bar:10}`{r_bar}'
|
| 101 |
+
if fmt['ascii'] is False:
|
| 102 |
+
fmt['ascii'] = [":black_square:", ":small_blue_diamond:", ":large_blue_diamond:",
|
| 103 |
+
":large_blue_square:"]
|
| 104 |
+
fmt['ncols'] = 336
|
| 105 |
+
self.sio.write(self.format_meter(**fmt))
|
| 106 |
+
|
| 107 |
+
def clear(self, *args, **kwargs):
|
| 108 |
+
super().clear(*args, **kwargs)
|
| 109 |
+
if not self.disable:
|
| 110 |
+
self.sio.write("")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def tsrange(*args, **kwargs):
|
| 114 |
+
"""Shortcut for `tqdm.contrib.slack.tqdm(range(*args), **kwargs)`."""
|
| 115 |
+
return tqdm_slack(range(*args), **kwargs)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Aliases
|
| 119 |
+
tqdm = tqdm_slack
|
| 120 |
+
trange = tsrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/telegram.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sends updates to a Telegram bot.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.contrib.telegram import tqdm, trange
|
| 6 |
+
>>> for i in trange(10, token='{token}', chat_id='{chat_id}'):
|
| 7 |
+
... ...
|
| 8 |
+
|
| 9 |
+

|
| 10 |
+
"""
|
| 11 |
+
from os import getenv
|
| 12 |
+
from warnings import warn
|
| 13 |
+
|
| 14 |
+
from requests import Session
|
| 15 |
+
|
| 16 |
+
from ..auto import tqdm as tqdm_auto
|
| 17 |
+
from ..std import TqdmWarning
|
| 18 |
+
from .utils_worker import MonoWorker
|
| 19 |
+
|
| 20 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 21 |
+
__all__ = ['TelegramIO', 'tqdm_telegram', 'ttgrange', 'tqdm', 'trange']
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class TelegramIO(MonoWorker):
|
| 25 |
+
"""Non-blocking file-like IO using a Telegram Bot."""
|
| 26 |
+
API = 'https://api.telegram.org/bot'
|
| 27 |
+
|
| 28 |
+
def __init__(self, token, chat_id):
|
| 29 |
+
"""Creates a new message in the given `chat_id`."""
|
| 30 |
+
super().__init__()
|
| 31 |
+
self.token = token
|
| 32 |
+
self.chat_id = chat_id
|
| 33 |
+
self.session = Session()
|
| 34 |
+
self.text = self.__class__.__name__
|
| 35 |
+
self.message_id
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def message_id(self):
|
| 39 |
+
if hasattr(self, '_message_id'):
|
| 40 |
+
return self._message_id
|
| 41 |
+
try:
|
| 42 |
+
res = self.session.post(
|
| 43 |
+
self.API + '%s/sendMessage' % self.token,
|
| 44 |
+
data={'text': '`' + self.text + '`', 'chat_id': self.chat_id,
|
| 45 |
+
'parse_mode': 'MarkdownV2'}).json()
|
| 46 |
+
except Exception as e:
|
| 47 |
+
tqdm_auto.write(str(e))
|
| 48 |
+
else:
|
| 49 |
+
if res.get('error_code') == 429:
|
| 50 |
+
warn("Creation rate limit: try increasing `mininterval`.",
|
| 51 |
+
TqdmWarning, stacklevel=2)
|
| 52 |
+
else:
|
| 53 |
+
self._message_id = res['result']['message_id']
|
| 54 |
+
return self._message_id
|
| 55 |
+
|
| 56 |
+
def write(self, s):
|
| 57 |
+
"""Replaces internal `message_id`'s text with `s`."""
|
| 58 |
+
if not s:
|
| 59 |
+
s = "..."
|
| 60 |
+
s = s.replace('\r', '').strip()
|
| 61 |
+
if s == self.text:
|
| 62 |
+
return # avoid duplicate message Bot error
|
| 63 |
+
message_id = self.message_id
|
| 64 |
+
if message_id is None:
|
| 65 |
+
return
|
| 66 |
+
self.text = s
|
| 67 |
+
try:
|
| 68 |
+
future = self.submit(
|
| 69 |
+
self.session.post, self.API + '%s/editMessageText' % self.token,
|
| 70 |
+
data={'text': '`' + s + '`', 'chat_id': self.chat_id,
|
| 71 |
+
'message_id': message_id, 'parse_mode': 'MarkdownV2'})
|
| 72 |
+
except Exception as e:
|
| 73 |
+
tqdm_auto.write(str(e))
|
| 74 |
+
else:
|
| 75 |
+
return future
|
| 76 |
+
|
| 77 |
+
def delete(self):
|
| 78 |
+
"""Deletes internal `message_id`."""
|
| 79 |
+
try:
|
| 80 |
+
future = self.submit(
|
| 81 |
+
self.session.post, self.API + '%s/deleteMessage' % self.token,
|
| 82 |
+
data={'chat_id': self.chat_id, 'message_id': self.message_id})
|
| 83 |
+
except Exception as e:
|
| 84 |
+
tqdm_auto.write(str(e))
|
| 85 |
+
else:
|
| 86 |
+
return future
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class tqdm_telegram(tqdm_auto):
|
| 90 |
+
"""
|
| 91 |
+
Standard `tqdm.auto.tqdm` but also sends updates to a Telegram Bot.
|
| 92 |
+
May take a few seconds to create (`__init__`).
|
| 93 |
+
|
| 94 |
+
- create a bot <https://core.telegram.org/bots#6-botfather>
|
| 95 |
+
- copy its `{token}`
|
| 96 |
+
- add the bot to a chat and send it a message such as `/start`
|
| 97 |
+
- go to <https://api.telegram.org/bot`{token}`/getUpdates> to find out
|
| 98 |
+
the `{chat_id}`
|
| 99 |
+
- paste the `{token}` & `{chat_id}` below
|
| 100 |
+
|
| 101 |
+
>>> from tqdm.contrib.telegram import tqdm, trange
|
| 102 |
+
>>> for i in tqdm(iterable, token='{token}', chat_id='{chat_id}'):
|
| 103 |
+
... ...
|
| 104 |
+
"""
|
| 105 |
+
def __init__(self, *args, **kwargs):
|
| 106 |
+
"""
|
| 107 |
+
Parameters
|
| 108 |
+
----------
|
| 109 |
+
token : str, required. Telegram token
|
| 110 |
+
[default: ${TQDM_TELEGRAM_TOKEN}].
|
| 111 |
+
chat_id : str, required. Telegram chat ID
|
| 112 |
+
[default: ${TQDM_TELEGRAM_CHAT_ID}].
|
| 113 |
+
|
| 114 |
+
See `tqdm.auto.tqdm.__init__` for other parameters.
|
| 115 |
+
"""
|
| 116 |
+
if not kwargs.get('disable'):
|
| 117 |
+
kwargs = kwargs.copy()
|
| 118 |
+
self.tgio = TelegramIO(
|
| 119 |
+
kwargs.pop('token', getenv('TQDM_TELEGRAM_TOKEN')),
|
| 120 |
+
kwargs.pop('chat_id', getenv('TQDM_TELEGRAM_CHAT_ID')))
|
| 121 |
+
super().__init__(*args, **kwargs)
|
| 122 |
+
|
| 123 |
+
def display(self, **kwargs):
|
| 124 |
+
super().display(**kwargs)
|
| 125 |
+
fmt = self.format_dict
|
| 126 |
+
if fmt.get('bar_format', None):
|
| 127 |
+
fmt['bar_format'] = fmt['bar_format'].replace(
|
| 128 |
+
'<bar/>', '{bar:10u}').replace('{bar}', '{bar:10u}')
|
| 129 |
+
else:
|
| 130 |
+
fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
|
| 131 |
+
self.tgio.write(self.format_meter(**fmt))
|
| 132 |
+
|
| 133 |
+
def clear(self, *args, **kwargs):
|
| 134 |
+
super().clear(*args, **kwargs)
|
| 135 |
+
if not self.disable:
|
| 136 |
+
self.tgio.write("")
|
| 137 |
+
|
| 138 |
+
def close(self):
|
| 139 |
+
if self.disable:
|
| 140 |
+
return
|
| 141 |
+
super().close()
|
| 142 |
+
if not (self.leave or (self.leave is None and self.pos == 0)):
|
| 143 |
+
self.tgio.delete()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def ttgrange(*args, **kwargs):
|
| 147 |
+
"""Shortcut for `tqdm.contrib.telegram.tqdm(range(*args), **kwargs)`."""
|
| 148 |
+
return tqdm_telegram(range(*args), **kwargs)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# Aliases
|
| 152 |
+
tqdm = tqdm_telegram
|
| 153 |
+
trange = ttgrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/contrib/utils_worker.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IO/concurrency helpers for `tqdm.contrib`.
|
| 3 |
+
"""
|
| 4 |
+
from collections import deque
|
| 5 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 6 |
+
|
| 7 |
+
from ..auto import tqdm as tqdm_auto
|
| 8 |
+
|
| 9 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 10 |
+
__all__ = ['MonoWorker']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MonoWorker:
|
| 14 |
+
"""
|
| 15 |
+
Supports one running task and one waiting task.
|
| 16 |
+
The waiting task is the most recent submitted (others are discarded).
|
| 17 |
+
"""
|
| 18 |
+
def __init__(self):
|
| 19 |
+
self.pool = ThreadPoolExecutor(max_workers=1)
|
| 20 |
+
self.futures = deque([], 2)
|
| 21 |
+
|
| 22 |
+
def submit(self, func, *args, **kwargs):
|
| 23 |
+
"""`func(*args, **kwargs)` may replace currently waiting task."""
|
| 24 |
+
futures = self.futures
|
| 25 |
+
if len(futures) == futures.maxlen:
|
| 26 |
+
running = futures.popleft()
|
| 27 |
+
if not running.done():
|
| 28 |
+
if len(futures): # clear waiting
|
| 29 |
+
waiting = futures.pop()
|
| 30 |
+
waiting.cancel()
|
| 31 |
+
futures.appendleft(running) # re-insert running
|
| 32 |
+
try:
|
| 33 |
+
waiting = self.pool.submit(func, *args, **kwargs)
|
| 34 |
+
except Exception as e:
|
| 35 |
+
tqdm_auto.write(str(e))
|
| 36 |
+
else:
|
| 37 |
+
futures.append(waiting)
|
| 38 |
+
return waiting
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/dask.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import partial
|
| 2 |
+
|
| 3 |
+
from dask.callbacks import Callback
|
| 4 |
+
|
| 5 |
+
from .auto import tqdm as tqdm_auto
|
| 6 |
+
|
| 7 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 8 |
+
__all__ = ['TqdmCallback']
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TqdmCallback(Callback):
|
| 12 |
+
"""Dask callback for task progress."""
|
| 13 |
+
def __init__(self, start=None, pretask=None, tqdm_class=tqdm_auto,
|
| 14 |
+
**tqdm_kwargs):
|
| 15 |
+
"""
|
| 16 |
+
Parameters
|
| 17 |
+
----------
|
| 18 |
+
tqdm_class : optional
|
| 19 |
+
`tqdm` class to use for bars [default: `tqdm.auto.tqdm`].
|
| 20 |
+
tqdm_kwargs : optional
|
| 21 |
+
Any other arguments used for all bars.
|
| 22 |
+
"""
|
| 23 |
+
super().__init__(start=start, pretask=pretask)
|
| 24 |
+
if tqdm_kwargs:
|
| 25 |
+
tqdm_class = partial(tqdm_class, **tqdm_kwargs)
|
| 26 |
+
self.tqdm_class = tqdm_class
|
| 27 |
+
|
| 28 |
+
def _start_state(self, _, state):
|
| 29 |
+
self.pbar = self.tqdm_class(total=sum(
|
| 30 |
+
len(state[k]) for k in ['ready', 'waiting', 'running', 'finished']))
|
| 31 |
+
|
| 32 |
+
def _posttask(self, *_, **__):
|
| 33 |
+
self.pbar.update()
|
| 34 |
+
|
| 35 |
+
def _finish(self, *_, **__):
|
| 36 |
+
self.pbar.close()
|
| 37 |
+
|
| 38 |
+
def display(self):
|
| 39 |
+
"""Displays in the current cell in Notebooks."""
|
| 40 |
+
container = getattr(self.bar, 'container', None)
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Matplotlib GUI progressbar decorator for iterators.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.gui import trange, tqdm
|
| 6 |
+
>>> for i in trange(10):
|
| 7 |
+
... ...
|
| 8 |
+
"""
|
| 9 |
+
# future division is important to divide integers and get as
|
| 10 |
+
# a result precise floating numbers (instead of truncated int)
|
| 11 |
+
import re
|
| 12 |
+
from warnings import warn
|
| 13 |
+
|
| 14 |
+
# to inherit from the tqdm class
|
| 15 |
+
from .std import TqdmExperimentalWarning
|
| 16 |
+
from .std import tqdm as std_tqdm
|
| 17 |
+
|
| 18 |
+
# import compatibility functions and utilities
|
| 19 |
+
|
| 20 |
+
__author__ = {"github.com/": ["casperdcl", "lrq3000"]}
|
| 21 |
+
__all__ = ['tqdm_gui', 'tgrange', 'tqdm', 'trange']
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class tqdm_gui(std_tqdm): # pragma: no cover
|
| 25 |
+
"""Experimental Matplotlib GUI version of tqdm!"""
|
| 26 |
+
# TODO: @classmethod: write() on GUI?
|
| 27 |
+
def __init__(self, *args, **kwargs):
|
| 28 |
+
from collections import deque
|
| 29 |
+
|
| 30 |
+
import matplotlib as mpl
|
| 31 |
+
import matplotlib.pyplot as plt
|
| 32 |
+
kwargs = kwargs.copy()
|
| 33 |
+
kwargs['gui'] = True
|
| 34 |
+
colour = kwargs.pop('colour', 'g')
|
| 35 |
+
super().__init__(*args, **kwargs)
|
| 36 |
+
|
| 37 |
+
if self.disable:
|
| 38 |
+
return
|
| 39 |
+
|
| 40 |
+
warn("GUI is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
|
| 41 |
+
self.mpl = mpl
|
| 42 |
+
self.plt = plt
|
| 43 |
+
|
| 44 |
+
# Remember if external environment uses toolbars
|
| 45 |
+
self.toolbar = self.mpl.rcParams['toolbar']
|
| 46 |
+
self.mpl.rcParams['toolbar'] = 'None'
|
| 47 |
+
|
| 48 |
+
self.mininterval = max(self.mininterval, 0.5)
|
| 49 |
+
self.fig, ax = plt.subplots(figsize=(9, 2.2))
|
| 50 |
+
# self.fig.subplots_adjust(bottom=0.2)
|
| 51 |
+
total = self.__len__() # avoids TypeError on None #971
|
| 52 |
+
if total is not None:
|
| 53 |
+
self.xdata = []
|
| 54 |
+
self.ydata = []
|
| 55 |
+
self.zdata = []
|
| 56 |
+
else:
|
| 57 |
+
self.xdata = deque([])
|
| 58 |
+
self.ydata = deque([])
|
| 59 |
+
self.zdata = deque([])
|
| 60 |
+
self.line1, = ax.plot(self.xdata, self.ydata, color='b')
|
| 61 |
+
self.line2, = ax.plot(self.xdata, self.zdata, color='k')
|
| 62 |
+
ax.set_ylim(0, 0.001)
|
| 63 |
+
if total is not None:
|
| 64 |
+
ax.set_xlim(0, 100)
|
| 65 |
+
ax.set_xlabel("percent")
|
| 66 |
+
self.fig.legend((self.line1, self.line2), ("cur", "est"),
|
| 67 |
+
loc='center right')
|
| 68 |
+
# progressbar
|
| 69 |
+
self.hspan = plt.axhspan(0, 0.001, xmin=0, xmax=0, color=colour)
|
| 70 |
+
else:
|
| 71 |
+
# ax.set_xlim(-60, 0)
|
| 72 |
+
ax.set_xlim(0, 60)
|
| 73 |
+
ax.invert_xaxis()
|
| 74 |
+
ax.set_xlabel("seconds")
|
| 75 |
+
ax.legend(("cur", "est"), loc='lower left')
|
| 76 |
+
ax.grid()
|
| 77 |
+
# ax.set_xlabel('seconds')
|
| 78 |
+
ax.set_ylabel((self.unit if self.unit else "it") + "/s")
|
| 79 |
+
if self.unit_scale:
|
| 80 |
+
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
|
| 81 |
+
ax.yaxis.get_offset_text().set_x(-0.15)
|
| 82 |
+
|
| 83 |
+
# Remember if external environment is interactive
|
| 84 |
+
self.wasion = plt.isinteractive()
|
| 85 |
+
plt.ion()
|
| 86 |
+
self.ax = ax
|
| 87 |
+
|
| 88 |
+
def close(self):
|
| 89 |
+
if self.disable:
|
| 90 |
+
return
|
| 91 |
+
|
| 92 |
+
self.disable = True
|
| 93 |
+
|
| 94 |
+
with self.get_lock():
|
| 95 |
+
self._instances.remove(self)
|
| 96 |
+
|
| 97 |
+
# Restore toolbars
|
| 98 |
+
self.mpl.rcParams['toolbar'] = self.toolbar
|
| 99 |
+
# Return to non-interactive mode
|
| 100 |
+
if not self.wasion:
|
| 101 |
+
self.plt.ioff()
|
| 102 |
+
if self.leave:
|
| 103 |
+
self.display()
|
| 104 |
+
else:
|
| 105 |
+
self.plt.close(self.fig)
|
| 106 |
+
|
| 107 |
+
def clear(self, *_, **__):
|
| 108 |
+
pass
|
| 109 |
+
|
| 110 |
+
def display(self, *_, **__):
|
| 111 |
+
n = self.n
|
| 112 |
+
cur_t = self._time()
|
| 113 |
+
elapsed = cur_t - self.start_t
|
| 114 |
+
delta_it = n - self.last_print_n
|
| 115 |
+
delta_t = cur_t - self.last_print_t
|
| 116 |
+
|
| 117 |
+
# Inline due to multiple calls
|
| 118 |
+
total = self.total
|
| 119 |
+
xdata = self.xdata
|
| 120 |
+
ydata = self.ydata
|
| 121 |
+
zdata = self.zdata
|
| 122 |
+
ax = self.ax
|
| 123 |
+
line1 = self.line1
|
| 124 |
+
line2 = self.line2
|
| 125 |
+
hspan = getattr(self, 'hspan', None)
|
| 126 |
+
# instantaneous rate
|
| 127 |
+
y = delta_it / delta_t
|
| 128 |
+
# overall rate
|
| 129 |
+
z = n / elapsed
|
| 130 |
+
# update line data
|
| 131 |
+
xdata.append(n * 100.0 / total if total else cur_t)
|
| 132 |
+
ydata.append(y)
|
| 133 |
+
zdata.append(z)
|
| 134 |
+
|
| 135 |
+
# Discard old values
|
| 136 |
+
# xmin, xmax = ax.get_xlim()
|
| 137 |
+
# if (not total) and elapsed > xmin * 1.1:
|
| 138 |
+
if (not total) and elapsed > 66:
|
| 139 |
+
xdata.popleft()
|
| 140 |
+
ydata.popleft()
|
| 141 |
+
zdata.popleft()
|
| 142 |
+
|
| 143 |
+
ymin, ymax = ax.get_ylim()
|
| 144 |
+
if y > ymax or z > ymax:
|
| 145 |
+
ymax = 1.1 * y
|
| 146 |
+
ax.set_ylim(ymin, ymax)
|
| 147 |
+
ax.figure.canvas.draw()
|
| 148 |
+
|
| 149 |
+
if total:
|
| 150 |
+
line1.set_data(xdata, ydata)
|
| 151 |
+
line2.set_data(xdata, zdata)
|
| 152 |
+
if hspan:
|
| 153 |
+
hspan.set_xy((0, ymin))
|
| 154 |
+
hspan.set_height(ymax - ymin)
|
| 155 |
+
hspan.set_width(n / total)
|
| 156 |
+
else:
|
| 157 |
+
t_ago = [cur_t - i for i in xdata]
|
| 158 |
+
line1.set_data(t_ago, ydata)
|
| 159 |
+
line2.set_data(t_ago, zdata)
|
| 160 |
+
|
| 161 |
+
d = self.format_dict
|
| 162 |
+
# remove {bar}
|
| 163 |
+
d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
|
| 164 |
+
"{bar}", "<bar/>")
|
| 165 |
+
msg = self.format_meter(**d)
|
| 166 |
+
if '<bar/>' in msg:
|
| 167 |
+
msg = "".join(re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
|
| 168 |
+
ax.set_title(msg, fontname="DejaVu Sans Mono", fontsize=11)
|
| 169 |
+
self.plt.pause(1e-9)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def tgrange(*args, **kwargs):
|
| 173 |
+
"""Shortcut for `tqdm.gui.tqdm(range(*args), **kwargs)`."""
|
| 174 |
+
return tqdm_gui(range(*args), **kwargs)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# Aliases
|
| 178 |
+
tqdm = tqdm_gui
|
| 179 |
+
trange = tgrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/keras.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from copy import copy
|
| 2 |
+
from functools import partial
|
| 3 |
+
|
| 4 |
+
from .auto import tqdm as tqdm_auto
|
| 5 |
+
|
| 6 |
+
try:
|
| 7 |
+
import keras
|
| 8 |
+
except (ImportError, AttributeError) as e:
|
| 9 |
+
try:
|
| 10 |
+
from tensorflow import keras
|
| 11 |
+
except ImportError:
|
| 12 |
+
raise e
|
| 13 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 14 |
+
__all__ = ['TqdmCallback']
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class TqdmCallback(keras.callbacks.Callback):
|
| 18 |
+
"""Keras callback for epoch and batch progress."""
|
| 19 |
+
@staticmethod
|
| 20 |
+
def bar2callback(bar, pop=None, delta=(lambda logs: 1)):
|
| 21 |
+
def callback(_, logs=None):
|
| 22 |
+
n = delta(logs)
|
| 23 |
+
if logs:
|
| 24 |
+
if pop:
|
| 25 |
+
logs = copy(logs)
|
| 26 |
+
[logs.pop(i, 0) for i in pop]
|
| 27 |
+
bar.set_postfix(logs, refresh=False)
|
| 28 |
+
bar.update(n)
|
| 29 |
+
|
| 30 |
+
return callback
|
| 31 |
+
|
| 32 |
+
def __init__(self, epochs=None, data_size=None, batch_size=None, verbose=1,
|
| 33 |
+
tqdm_class=tqdm_auto, **tqdm_kwargs):
|
| 34 |
+
"""
|
| 35 |
+
Parameters
|
| 36 |
+
----------
|
| 37 |
+
epochs : int, optional
|
| 38 |
+
data_size : int, optional
|
| 39 |
+
Number of training pairs.
|
| 40 |
+
batch_size : int, optional
|
| 41 |
+
Number of training pairs per batch.
|
| 42 |
+
verbose : int
|
| 43 |
+
0: epoch, 1: batch (transient), 2: batch. [default: 1].
|
| 44 |
+
Will be set to `0` unless both `data_size` and `batch_size`
|
| 45 |
+
are given.
|
| 46 |
+
tqdm_class : optional
|
| 47 |
+
`tqdm` class to use for bars [default: `tqdm.auto.tqdm`].
|
| 48 |
+
tqdm_kwargs : optional
|
| 49 |
+
Any other arguments used for all bars.
|
| 50 |
+
"""
|
| 51 |
+
if tqdm_kwargs:
|
| 52 |
+
tqdm_class = partial(tqdm_class, **tqdm_kwargs)
|
| 53 |
+
self.tqdm_class = tqdm_class
|
| 54 |
+
self.epoch_bar = tqdm_class(total=epochs, unit='epoch')
|
| 55 |
+
self.on_epoch_end = self.bar2callback(self.epoch_bar)
|
| 56 |
+
if data_size and batch_size:
|
| 57 |
+
self.batches = batches = (data_size + batch_size - 1) // batch_size
|
| 58 |
+
else:
|
| 59 |
+
self.batches = batches = None
|
| 60 |
+
self.verbose = verbose
|
| 61 |
+
if verbose == 1:
|
| 62 |
+
self.batch_bar = tqdm_class(total=batches, unit='batch', leave=False)
|
| 63 |
+
self.on_batch_end = self.bar2callback(
|
| 64 |
+
self.batch_bar, pop=['batch', 'size'],
|
| 65 |
+
delta=lambda logs: logs.get('size', 1))
|
| 66 |
+
|
| 67 |
+
def on_train_begin(self, *_, **__):
|
| 68 |
+
params = self.params.get
|
| 69 |
+
auto_total = params('epochs', params('nb_epoch', None))
|
| 70 |
+
if auto_total is not None and auto_total != self.epoch_bar.total:
|
| 71 |
+
self.epoch_bar.reset(total=auto_total)
|
| 72 |
+
|
| 73 |
+
def on_epoch_begin(self, epoch, *_, **__):
|
| 74 |
+
if self.epoch_bar.n < epoch:
|
| 75 |
+
ebar = self.epoch_bar
|
| 76 |
+
ebar.n = ebar.last_print_n = ebar.initial = epoch
|
| 77 |
+
if self.verbose:
|
| 78 |
+
params = self.params.get
|
| 79 |
+
total = params('samples', params(
|
| 80 |
+
'nb_sample', params('steps', None))) or self.batches
|
| 81 |
+
if self.verbose == 2:
|
| 82 |
+
if hasattr(self, 'batch_bar'):
|
| 83 |
+
self.batch_bar.close()
|
| 84 |
+
self.batch_bar = self.tqdm_class(
|
| 85 |
+
total=total, unit='batch', leave=True,
|
| 86 |
+
unit_scale=1 / (params('batch_size', 1) or 1))
|
| 87 |
+
self.on_batch_end = self.bar2callback(
|
| 88 |
+
self.batch_bar, pop=['batch', 'size'],
|
| 89 |
+
delta=lambda logs: logs.get('size', 1))
|
| 90 |
+
elif self.verbose == 1:
|
| 91 |
+
self.batch_bar.unit_scale = 1 / (params('batch_size', 1) or 1)
|
| 92 |
+
self.batch_bar.reset(total=total)
|
| 93 |
+
else:
|
| 94 |
+
raise KeyError('Unknown verbosity')
|
| 95 |
+
|
| 96 |
+
def on_train_end(self, *_, **__):
|
| 97 |
+
if hasattr(self, 'batch_bar'):
|
| 98 |
+
self.batch_bar.close()
|
| 99 |
+
self.epoch_bar.close()
|
| 100 |
+
|
| 101 |
+
def display(self):
|
| 102 |
+
"""Displays in the current cell in Notebooks."""
|
| 103 |
+
container = getattr(self.epoch_bar, 'container', None)
|
| 104 |
+
if container is None:
|
| 105 |
+
return
|
| 106 |
+
from .notebook import display
|
| 107 |
+
display(container)
|
| 108 |
+
batch_bar = getattr(self, 'batch_bar', None)
|
| 109 |
+
if batch_bar is not None:
|
| 110 |
+
display(batch_bar.container)
|
| 111 |
+
|
| 112 |
+
@staticmethod
|
| 113 |
+
def _implements_train_batch_hooks():
|
| 114 |
+
return True
|
| 115 |
+
|
| 116 |
+
@staticmethod
|
| 117 |
+
def _implements_test_batch_hooks():
|
| 118 |
+
return True
|
| 119 |
+
|
| 120 |
+
@staticmethod
|
| 121 |
+
def _implements_predict_batch_hooks():
|
| 122 |
+
return True
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/notebook.py
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IPython/Jupyter Notebook progressbar decorator for iterators.
|
| 3 |
+
Includes a default `range` iterator printing to `stderr`.
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
>>> from tqdm.notebook import trange, tqdm
|
| 7 |
+
>>> for i in trange(10):
|
| 8 |
+
... ...
|
| 9 |
+
"""
|
| 10 |
+
# import compatibility functions and utilities
|
| 11 |
+
import re
|
| 12 |
+
import sys
|
| 13 |
+
from html import escape
|
| 14 |
+
from weakref import proxy
|
| 15 |
+
|
| 16 |
+
# to inherit from the tqdm class
|
| 17 |
+
from .std import tqdm as std_tqdm
|
| 18 |
+
|
| 19 |
+
if True: # pragma: no cover
|
| 20 |
+
# import IPython/Jupyter base widget and display utilities
|
| 21 |
+
IPY = 0
|
| 22 |
+
try: # IPython 4.x
|
| 23 |
+
import ipywidgets
|
| 24 |
+
IPY = 4
|
| 25 |
+
except ImportError: # IPython 3.x / 2.x
|
| 26 |
+
IPY = 32
|
| 27 |
+
import warnings
|
| 28 |
+
with warnings.catch_warnings():
|
| 29 |
+
warnings.filterwarnings(
|
| 30 |
+
'ignore', message=".*The `IPython.html` package has been deprecated.*")
|
| 31 |
+
try:
|
| 32 |
+
import IPython.html.widgets as ipywidgets # NOQA: F401
|
| 33 |
+
except ImportError:
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
try: # IPython 4.x / 3.x
|
| 37 |
+
if IPY == 32:
|
| 38 |
+
from IPython.html.widgets import HTML
|
| 39 |
+
from IPython.html.widgets import FloatProgress as IProgress
|
| 40 |
+
from IPython.html.widgets import HBox
|
| 41 |
+
IPY = 3
|
| 42 |
+
else:
|
| 43 |
+
from ipywidgets import HTML
|
| 44 |
+
from ipywidgets import FloatProgress as IProgress
|
| 45 |
+
from ipywidgets import HBox
|
| 46 |
+
except ImportError:
|
| 47 |
+
try: # IPython 2.x
|
| 48 |
+
from IPython.html.widgets import HTML
|
| 49 |
+
from IPython.html.widgets import ContainerWidget as HBox
|
| 50 |
+
from IPython.html.widgets import FloatProgressWidget as IProgress
|
| 51 |
+
IPY = 2
|
| 52 |
+
except ImportError:
|
| 53 |
+
IPY = 0
|
| 54 |
+
IProgress = None
|
| 55 |
+
HBox = object
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
from IPython.display import display # , clear_output
|
| 59 |
+
except ImportError:
|
| 60 |
+
pass
|
| 61 |
+
|
| 62 |
+
__author__ = {"github.com/": ["lrq3000", "casperdcl", "alexanderkuk"]}
|
| 63 |
+
__all__ = ['tqdm_notebook', 'tnrange', 'tqdm', 'trange']
|
| 64 |
+
WARN_NOIPYW = ("IProgress not found. Please update jupyter and ipywidgets."
|
| 65 |
+
" See https://ipywidgets.readthedocs.io/en/stable"
|
| 66 |
+
"/user_install.html")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class TqdmHBox(HBox):
|
| 70 |
+
"""`ipywidgets.HBox` with a pretty representation"""
|
| 71 |
+
def _json_(self, pretty=None):
|
| 72 |
+
pbar = getattr(self, 'pbar', None)
|
| 73 |
+
if pbar is None:
|
| 74 |
+
return {}
|
| 75 |
+
d = pbar.format_dict
|
| 76 |
+
if pretty is not None:
|
| 77 |
+
d["ascii"] = not pretty
|
| 78 |
+
return d
|
| 79 |
+
|
| 80 |
+
def __repr__(self, pretty=False):
|
| 81 |
+
pbar = getattr(self, 'pbar', None)
|
| 82 |
+
if pbar is None:
|
| 83 |
+
return super().__repr__()
|
| 84 |
+
return pbar.format_meter(**self._json_(pretty))
|
| 85 |
+
|
| 86 |
+
def _repr_pretty_(self, pp, *_, **__):
|
| 87 |
+
pp.text(self.__repr__(True))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class tqdm_notebook(std_tqdm):
|
| 91 |
+
"""
|
| 92 |
+
Experimental IPython/Jupyter Notebook widget using tqdm!
|
| 93 |
+
"""
|
| 94 |
+
@staticmethod
|
| 95 |
+
def status_printer(_, total=None, desc=None, ncols=None):
|
| 96 |
+
"""
|
| 97 |
+
Manage the printing of an IPython/Jupyter Notebook progress bar widget.
|
| 98 |
+
"""
|
| 99 |
+
# Fallback to text bar if there's no total
|
| 100 |
+
# DEPRECATED: replaced with an 'info' style bar
|
| 101 |
+
# if not total:
|
| 102 |
+
# return super(tqdm_notebook, tqdm_notebook).status_printer(file)
|
| 103 |
+
|
| 104 |
+
# fp = file
|
| 105 |
+
|
| 106 |
+
# Prepare IPython progress bar
|
| 107 |
+
if IProgress is None: # #187 #451 #558 #872
|
| 108 |
+
raise ImportError(WARN_NOIPYW)
|
| 109 |
+
if total:
|
| 110 |
+
pbar = IProgress(min=0, max=total)
|
| 111 |
+
else: # No total? Show info style bar with no progress tqdm status
|
| 112 |
+
pbar = IProgress(min=0, max=1)
|
| 113 |
+
pbar.value = 1
|
| 114 |
+
pbar.bar_style = 'info'
|
| 115 |
+
if ncols is None:
|
| 116 |
+
pbar.layout.width = "20px"
|
| 117 |
+
|
| 118 |
+
ltext = HTML()
|
| 119 |
+
rtext = HTML()
|
| 120 |
+
if desc:
|
| 121 |
+
ltext.value = desc
|
| 122 |
+
container = TqdmHBox(children=[ltext, pbar, rtext])
|
| 123 |
+
# Prepare layout
|
| 124 |
+
if ncols is not None: # use default style of ipywidgets
|
| 125 |
+
# ncols could be 100, "100px", "100%"
|
| 126 |
+
ncols = str(ncols) # ipywidgets only accepts string
|
| 127 |
+
try:
|
| 128 |
+
if int(ncols) > 0: # isnumeric and positive
|
| 129 |
+
ncols += 'px'
|
| 130 |
+
except ValueError:
|
| 131 |
+
pass
|
| 132 |
+
pbar.layout.flex = '2'
|
| 133 |
+
container.layout.width = ncols
|
| 134 |
+
container.layout.display = 'inline-flex'
|
| 135 |
+
container.layout.flex_flow = 'row wrap'
|
| 136 |
+
|
| 137 |
+
return container
|
| 138 |
+
|
| 139 |
+
def display(self, msg=None, pos=None,
|
| 140 |
+
# additional signals
|
| 141 |
+
close=False, bar_style=None, check_delay=True):
|
| 142 |
+
# Note: contrary to native tqdm, msg='' does NOT clear bar
|
| 143 |
+
# goal is to keep all infos if error happens so user knows
|
| 144 |
+
# at which iteration the loop failed.
|
| 145 |
+
|
| 146 |
+
# Clear previous output (really necessary?)
|
| 147 |
+
# clear_output(wait=1)
|
| 148 |
+
|
| 149 |
+
if not msg and not close:
|
| 150 |
+
d = self.format_dict
|
| 151 |
+
# remove {bar}
|
| 152 |
+
d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
|
| 153 |
+
"{bar}", "<bar/>")
|
| 154 |
+
msg = self.format_meter(**d)
|
| 155 |
+
|
| 156 |
+
ltext, pbar, rtext = self.container.children
|
| 157 |
+
pbar.value = self.n
|
| 158 |
+
|
| 159 |
+
if msg:
|
| 160 |
+
msg = msg.replace(' ', '\u2007') # fix html space padding
|
| 161 |
+
# html escape special characters (like '&')
|
| 162 |
+
if '<bar/>' in msg:
|
| 163 |
+
left, right = map(escape, re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
|
| 164 |
+
else:
|
| 165 |
+
left, right = '', escape(msg)
|
| 166 |
+
|
| 167 |
+
# Update description
|
| 168 |
+
ltext.value = left
|
| 169 |
+
# never clear the bar (signal: msg='')
|
| 170 |
+
if right:
|
| 171 |
+
rtext.value = right
|
| 172 |
+
|
| 173 |
+
# Change bar style
|
| 174 |
+
if bar_style:
|
| 175 |
+
# Hack-ish way to avoid the danger bar_style being overridden by
|
| 176 |
+
# success because the bar gets closed after the error...
|
| 177 |
+
if pbar.bar_style != 'danger' or bar_style != 'success':
|
| 178 |
+
pbar.bar_style = bar_style
|
| 179 |
+
|
| 180 |
+
# Special signal to close the bar
|
| 181 |
+
if close and pbar.bar_style != 'danger': # hide only if no error
|
| 182 |
+
try:
|
| 183 |
+
self.container.close()
|
| 184 |
+
except AttributeError:
|
| 185 |
+
self.container.visible = False
|
| 186 |
+
self.container.layout.visibility = 'hidden' # IPYW>=8
|
| 187 |
+
|
| 188 |
+
if check_delay and self.delay > 0 and not self.displayed:
|
| 189 |
+
display(self.container)
|
| 190 |
+
self.displayed = True
|
| 191 |
+
|
| 192 |
+
@property
|
| 193 |
+
def colour(self):
|
| 194 |
+
if hasattr(self, 'container'):
|
| 195 |
+
return self.container.children[-2].style.bar_color
|
| 196 |
+
|
| 197 |
+
@colour.setter
|
| 198 |
+
def colour(self, bar_color):
|
| 199 |
+
if hasattr(self, 'container'):
|
| 200 |
+
self.container.children[-2].style.bar_color = bar_color
|
| 201 |
+
|
| 202 |
+
def __init__(self, *args, **kwargs):
|
| 203 |
+
"""
|
| 204 |
+
Supports the usual `tqdm.tqdm` parameters as well as those listed below.
|
| 205 |
+
|
| 206 |
+
Parameters
|
| 207 |
+
----------
|
| 208 |
+
display : Whether to call `display(self.container)` immediately
|
| 209 |
+
[default: True].
|
| 210 |
+
"""
|
| 211 |
+
kwargs = kwargs.copy()
|
| 212 |
+
# Setup default output
|
| 213 |
+
file_kwarg = kwargs.get('file', sys.stderr)
|
| 214 |
+
if file_kwarg is sys.stderr or file_kwarg is None:
|
| 215 |
+
kwargs['file'] = sys.stdout # avoid the red block in IPython
|
| 216 |
+
|
| 217 |
+
# Initialize parent class + avoid printing by using gui=True
|
| 218 |
+
kwargs['gui'] = True
|
| 219 |
+
# convert disable = None to False
|
| 220 |
+
kwargs['disable'] = bool(kwargs.get('disable', False))
|
| 221 |
+
colour = kwargs.pop('colour', None)
|
| 222 |
+
display_here = kwargs.pop('display', True)
|
| 223 |
+
super().__init__(*args, **kwargs)
|
| 224 |
+
if self.disable or not kwargs['gui']:
|
| 225 |
+
self.disp = lambda *_, **__: None
|
| 226 |
+
return
|
| 227 |
+
|
| 228 |
+
# Get bar width
|
| 229 |
+
self.ncols = '100%' if self.dynamic_ncols else kwargs.get("ncols", None)
|
| 230 |
+
|
| 231 |
+
# Replace with IPython progress bar display (with correct total)
|
| 232 |
+
unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
|
| 233 |
+
total = self.total * unit_scale if self.total else self.total
|
| 234 |
+
self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
|
| 235 |
+
self.container.pbar = proxy(self)
|
| 236 |
+
self.displayed = False
|
| 237 |
+
if display_here and self.delay <= 0:
|
| 238 |
+
display(self.container)
|
| 239 |
+
self.displayed = True
|
| 240 |
+
self.disp = self.display
|
| 241 |
+
self.colour = colour
|
| 242 |
+
|
| 243 |
+
# Print initial bar state
|
| 244 |
+
if not self.disable:
|
| 245 |
+
self.display(check_delay=False)
|
| 246 |
+
|
| 247 |
+
def __iter__(self):
|
| 248 |
+
try:
|
| 249 |
+
it = super().__iter__()
|
| 250 |
+
yield from it
|
| 251 |
+
# NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
|
| 252 |
+
except: # NOQA
|
| 253 |
+
self.disp(bar_style='danger')
|
| 254 |
+
raise
|
| 255 |
+
# NB: don't `finally: close()`
|
| 256 |
+
# since this could be a shared bar which the user will `reset()`
|
| 257 |
+
|
| 258 |
+
def update(self, n=1):
|
| 259 |
+
try:
|
| 260 |
+
return super().update(n=n)
|
| 261 |
+
# NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
|
| 262 |
+
except: # NOQA
|
| 263 |
+
# cannot catch KeyboardInterrupt when using manual tqdm
|
| 264 |
+
# as the interrupt will most likely happen on another statement
|
| 265 |
+
self.disp(bar_style='danger')
|
| 266 |
+
raise
|
| 267 |
+
# NB: don't `finally: close()`
|
| 268 |
+
# since this could be a shared bar which the user will `reset()`
|
| 269 |
+
|
| 270 |
+
def close(self):
|
| 271 |
+
if self.disable:
|
| 272 |
+
return
|
| 273 |
+
super().close()
|
| 274 |
+
# Try to detect if there was an error or KeyboardInterrupt
|
| 275 |
+
# in manual mode: if n < total, things probably got wrong
|
| 276 |
+
if self.total and self.n < self.total:
|
| 277 |
+
self.disp(bar_style='danger', check_delay=False)
|
| 278 |
+
else:
|
| 279 |
+
if self.leave:
|
| 280 |
+
self.disp(bar_style='success', check_delay=False)
|
| 281 |
+
else:
|
| 282 |
+
self.disp(close=True, check_delay=False)
|
| 283 |
+
|
| 284 |
+
def clear(self, *_, **__):
|
| 285 |
+
pass
|
| 286 |
+
|
| 287 |
+
def reset(self, total=None):
|
| 288 |
+
"""
|
| 289 |
+
Resets to 0 iterations for repeated use.
|
| 290 |
+
|
| 291 |
+
Consider combining with `leave=True`.
|
| 292 |
+
|
| 293 |
+
Parameters
|
| 294 |
+
----------
|
| 295 |
+
total : int or float, optional. Total to use for the new bar.
|
| 296 |
+
"""
|
| 297 |
+
if self.disable:
|
| 298 |
+
return super().reset(total=total)
|
| 299 |
+
_, pbar, _ = self.container.children
|
| 300 |
+
pbar.bar_style = ''
|
| 301 |
+
if total is not None:
|
| 302 |
+
pbar.max = total
|
| 303 |
+
if not self.total and self.ncols is None: # no longer unknown total
|
| 304 |
+
pbar.layout.width = None # reset width
|
| 305 |
+
return super().reset(total=total)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def tnrange(*args, **kwargs):
|
| 309 |
+
"""Shortcut for `tqdm.notebook.tqdm(range(*args), **kwargs)`."""
|
| 310 |
+
return tqdm_notebook(range(*args), **kwargs)
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
# Aliases
|
| 314 |
+
tqdm = tqdm_notebook
|
| 315 |
+
trange = tnrange
|
loan-advisor-agent/.venv/Lib/site-packages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tqdm.rich import trange, tqdm
|
| 6 |
+
>>> for i in trange(10):
|
| 7 |
+
... ...
|
| 8 |
+
"""
|
| 9 |
+
from warnings import warn
|
| 10 |
+
|
| 11 |
+
from rich.progress import (
|
| 12 |
+
BarColumn, Progress, ProgressColumn, Text, TimeElapsedColumn, TimeRemainingColumn, filesize)
|
| 13 |
+
|
| 14 |
+
from .std import TqdmExperimentalWarning
|
| 15 |
+
from .std import tqdm as std_tqdm
|
| 16 |
+
|
| 17 |
+
__author__ = {"github.com/": ["casperdcl"]}
|
| 18 |
+
__all__ = ['tqdm_rich', 'trrange', 'tqdm', 'trange']
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class FractionColumn(ProgressColumn):
|
| 22 |
+
"""Renders completed/total, e.g. '0.5/2.3 G'."""
|
| 23 |
+
def __init__(self, unit_scale=False, unit_divisor=1000):
|
| 24 |
+
self.unit_scale = unit_scale
|
| 25 |
+
self.unit_divisor = unit_divisor
|
| 26 |
+
super().__init__()
|
| 27 |
+
|
| 28 |
+
def render(self, task):
|
| 29 |
+
"""Calculate common unit for completed and total."""
|
| 30 |
+
completed = int(task.completed)
|
| 31 |
+
total = int(task.total)
|
| 32 |
+
if self.unit_scale:
|
| 33 |
+
unit, suffix = filesize.pick_unit_and_suffix(
|
| 34 |
+
total,
|
| 35 |
+
["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
|
| 36 |
+
self.unit_divisor,
|
| 37 |
+
)
|
| 38 |
+
else:
|
| 39 |
+
unit, suffix = filesize.pick_unit_and_suffix(total, [""], 1)
|
| 40 |
+
precision = 0 if unit == 1 else 1
|
| 41 |
+
return Text(
|
| 42 |
+
f"{completed/unit:,.{precision}f}/{total/unit:,.{precision}f} {suffix}",
|
| 43 |
+
style="progress.download")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class RateColumn(ProgressColumn):
|
| 47 |
+
"""Renders human readable transfer speed."""
|
| 48 |
+
def __init__(self, unit="", unit_scale=False, unit_divisor=1000):
|
| 49 |
+
self.unit = unit
|
| 50 |
+
self.unit_scale = unit_scale
|
| 51 |
+
self.unit_divisor = unit_divisor
|
| 52 |
+
super().__init__()
|
| 53 |
+
|
| 54 |
+
def render(self, task):
|
| 55 |
+
"""Show data transfer speed."""
|
| 56 |
+
speed = task.speed
|
| 57 |
+
if speed is None:
|
| 58 |
+
return Text(f"? {self.unit}/s", style="progress.data.speed")
|
| 59 |
+
if self.unit_scale:
|
| 60 |
+
unit, suffix = filesize.pick_unit_and_suffix(
|
| 61 |
+
speed,
|
| 62 |
+
["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
|
| 63 |
+
self.unit_divisor,
|
| 64 |
+
)
|
| 65 |
+
else:
|
| 66 |
+
unit, suffix = filesize.pick_unit_and_suffix(speed, [""], 1)
|
| 67 |
+
precision = 0 if unit == 1 else 1
|
| 68 |
+
return Text(f"{speed/unit:,.{precision}f} {suffix}{self.unit}/s",
|
| 69 |
+
style="progress.data.speed")
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class 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)
|
| 130 |
+
|
| 131 |
+
def reset(self, total=None):
|
| 132 |
+
"""
|
| 133 |
+
Resets to 0 iterations for repeated use.
|
| 134 |
+
|
| 135 |
+
Parameters
|
| 136 |
+
----------
|
| 137 |
+
total : int or float, optional. Total to use for the new bar.
|
| 138 |
+
"""
|
| 139 |
+
if hasattr(self, '_prog'):
|
| 140 |
+
self._prog.reset(total=total)
|
| 141 |
+
super().reset(total=total)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def trrange(*args, **kwargs):
|
| 145 |
+
"""Shortcut for `tqdm.rich.tqdm(range(*args), **kwargs)`."""
|
| 146 |
+
return tqdm_rich(range(*args), **kwargs)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# Aliases
|
| 150 |
+
tqdm = tqdm_rich
|
| 151 |
+
trange = trrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/std.py
ADDED
|
@@ -0,0 +1,1524 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Customisable progressbar decorator for iterators.
|
| 3 |
+
Includes a default `range` iterator printing to `stderr`.
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
>>> from tqdm import trange, tqdm
|
| 7 |
+
>>> for i in trange(10):
|
| 8 |
+
... ...
|
| 9 |
+
"""
|
| 10 |
+
import sys
|
| 11 |
+
from collections import OrderedDict, defaultdict
|
| 12 |
+
from contextlib import contextmanager
|
| 13 |
+
from datetime import datetime, timedelta, timezone
|
| 14 |
+
from numbers import Number
|
| 15 |
+
from time import time
|
| 16 |
+
from warnings import warn
|
| 17 |
+
from weakref import WeakSet
|
| 18 |
+
|
| 19 |
+
from ._monitor import TMonitor
|
| 20 |
+
from .utils import (
|
| 21 |
+
CallbackIOWrapper, Comparable, DisableOnWriteError, FormatReplace, SimpleTextIOWrapper,
|
| 22 |
+
_is_ascii, _screen_shape_wrapper, _supports_unicode, _term_move_up, disp_len, disp_trim,
|
| 23 |
+
envwrap)
|
| 24 |
+
|
| 25 |
+
__author__ = "https://github.com/tqdm/tqdm#contributions"
|
| 26 |
+
__all__ = ['tqdm', 'trange',
|
| 27 |
+
'TqdmTypeError', 'TqdmKeyError', 'TqdmWarning',
|
| 28 |
+
'TqdmExperimentalWarning', 'TqdmDeprecationWarning',
|
| 29 |
+
'TqdmMonitorWarning']
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TqdmTypeError(TypeError):
|
| 33 |
+
pass
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class TqdmKeyError(KeyError):
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class TqdmWarning(Warning):
|
| 41 |
+
"""base class for all tqdm warnings.
|
| 42 |
+
|
| 43 |
+
Used for non-external-code-breaking errors, such as garbled printing.
|
| 44 |
+
"""
|
| 45 |
+
def __init__(self, msg, fp_write=None): # noqa: B042
|
| 46 |
+
if fp_write is not None:
|
| 47 |
+
fp_write("\n" + self.__class__.__name__ + ": " + str(msg).rstrip() + '\n')
|
| 48 |
+
else:
|
| 49 |
+
super().__init__(msg)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class TqdmExperimentalWarning(TqdmWarning, FutureWarning):
|
| 53 |
+
"""beta feature, unstable API and behaviour"""
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class TqdmDeprecationWarning(TqdmWarning, DeprecationWarning):
|
| 58 |
+
# not suppressed if raised
|
| 59 |
+
pass
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class TqdmMonitorWarning(TqdmWarning, RuntimeWarning):
|
| 63 |
+
"""tqdm monitor errors which do not affect external functionality"""
|
| 64 |
+
pass
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def TRLock(*args, **kwargs):
|
| 68 |
+
"""threading RLock"""
|
| 69 |
+
try:
|
| 70 |
+
from threading import RLock
|
| 71 |
+
return RLock(*args, **kwargs)
|
| 72 |
+
except (ImportError, OSError): # pragma: no cover
|
| 73 |
+
pass
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class TqdmDefaultWriteLock:
|
| 77 |
+
"""
|
| 78 |
+
Provide a default write lock for thread and multiprocessing safety.
|
| 79 |
+
Works only on platforms supporting `fork` (so Windows is excluded).
|
| 80 |
+
You must initialise a `tqdm` or `TqdmDefaultWriteLock` instance
|
| 81 |
+
before forking in order for the write lock to work.
|
| 82 |
+
On Windows, you need to supply the lock from the parent to the children as
|
| 83 |
+
an argument to joblib or the parallelism lib you use.
|
| 84 |
+
"""
|
| 85 |
+
# global thread lock so no setup required for multithreading.
|
| 86 |
+
# NB: Do not create multiprocessing lock as it sets the multiprocessing
|
| 87 |
+
# context, disallowing `spawn()`/`forkserver()`
|
| 88 |
+
th_lock = TRLock()
|
| 89 |
+
|
| 90 |
+
def __init__(self):
|
| 91 |
+
# Create global parallelism locks to avoid racing issues with parallel
|
| 92 |
+
# bars works only if fork available (Linux/MacOSX, but not Windows)
|
| 93 |
+
cls = type(self)
|
| 94 |
+
root_lock = cls.th_lock
|
| 95 |
+
if root_lock is not None:
|
| 96 |
+
root_lock.acquire()
|
| 97 |
+
cls.create_mp_lock()
|
| 98 |
+
self.locks = [lk for lk in [cls.mp_lock, cls.th_lock] if lk is not None]
|
| 99 |
+
if root_lock is not None:
|
| 100 |
+
root_lock.release()
|
| 101 |
+
|
| 102 |
+
def acquire(self, *a, **k):
|
| 103 |
+
for lock in self.locks:
|
| 104 |
+
lock.acquire(*a, **k)
|
| 105 |
+
|
| 106 |
+
def release(self):
|
| 107 |
+
for lock in self.locks[::-1]: # Release in inverse order of acquisition
|
| 108 |
+
lock.release()
|
| 109 |
+
|
| 110 |
+
def __enter__(self):
|
| 111 |
+
self.acquire()
|
| 112 |
+
|
| 113 |
+
def __exit__(self, *exc):
|
| 114 |
+
self.release()
|
| 115 |
+
|
| 116 |
+
@classmethod
|
| 117 |
+
def create_mp_lock(cls):
|
| 118 |
+
if not hasattr(cls, 'mp_lock'):
|
| 119 |
+
try:
|
| 120 |
+
from multiprocessing import RLock
|
| 121 |
+
cls.mp_lock = RLock()
|
| 122 |
+
except (ImportError, OSError): # pragma: no cover
|
| 123 |
+
cls.mp_lock = None
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def create_th_lock(cls):
|
| 127 |
+
assert hasattr(cls, 'th_lock')
|
| 128 |
+
warn("create_th_lock not needed anymore", TqdmDeprecationWarning, stacklevel=2)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class Bar:
|
| 132 |
+
"""
|
| 133 |
+
`str.format`-able bar with format specifiers: `[width][type]`
|
| 134 |
+
|
| 135 |
+
- `width`
|
| 136 |
+
+ unspecified (default): use `self.default_len`
|
| 137 |
+
+ `int >= 0`: overrides `self.default_len`
|
| 138 |
+
+ `int < 0`: subtract from `self.default_len`
|
| 139 |
+
- `type`
|
| 140 |
+
+ `a`: ascii (`charset=self.ASCII` override)
|
| 141 |
+
+ `u`: unicode (`charset=self.UTF` override)
|
| 142 |
+
+ `b`: blank (`charset=" "` override)
|
| 143 |
+
"""
|
| 144 |
+
ASCII = " 123456789#"
|
| 145 |
+
UTF = " " + ''.join(map(chr, range(0x258F, 0x2587, -1)))
|
| 146 |
+
BLANK = " "
|
| 147 |
+
COLOUR_RESET = '\x1b[0m'
|
| 148 |
+
COLOUR_RGB = '\x1b[38;2;%d;%d;%dm'
|
| 149 |
+
COLOURS = {'BLACK': '\x1b[30m', 'RED': '\x1b[31m', 'GREEN': '\x1b[32m',
|
| 150 |
+
'YELLOW': '\x1b[33m', 'BLUE': '\x1b[34m', 'MAGENTA': '\x1b[35m',
|
| 151 |
+
'CYAN': '\x1b[36m', 'WHITE': '\x1b[37m'}
|
| 152 |
+
|
| 153 |
+
def __init__(self, frac, default_len=10, charset=UTF, colour=None):
|
| 154 |
+
if not 0 <= frac <= 1:
|
| 155 |
+
warn("clamping frac to range [0, 1]", TqdmWarning, stacklevel=2)
|
| 156 |
+
frac = max(0, min(1, frac))
|
| 157 |
+
assert default_len > 0
|
| 158 |
+
self.frac = frac
|
| 159 |
+
self.default_len = default_len
|
| 160 |
+
self.charset = charset
|
| 161 |
+
self.colour = colour
|
| 162 |
+
|
| 163 |
+
@property
|
| 164 |
+
def colour(self):
|
| 165 |
+
return self._colour
|
| 166 |
+
|
| 167 |
+
@colour.setter
|
| 168 |
+
def colour(self, value):
|
| 169 |
+
if not value:
|
| 170 |
+
self._colour = None
|
| 171 |
+
return
|
| 172 |
+
try:
|
| 173 |
+
if value.upper() in self.COLOURS:
|
| 174 |
+
self._colour = self.COLOURS[value.upper()]
|
| 175 |
+
elif value[0] == '#' and len(value) == 7:
|
| 176 |
+
self._colour = self.COLOUR_RGB % tuple(
|
| 177 |
+
int(i, 16) for i in (value[1:3], value[3:5], value[5:7]))
|
| 178 |
+
else:
|
| 179 |
+
raise KeyError
|
| 180 |
+
except (KeyError, AttributeError):
|
| 181 |
+
warn(f"Unknown colour ({value}); valid choices:"
|
| 182 |
+
f" [hex (#00ff00), {', '.join(self.COLOURS)}]", TqdmWarning, stacklevel=2)
|
| 183 |
+
self._colour = None
|
| 184 |
+
|
| 185 |
+
def __format__(self, format_spec):
|
| 186 |
+
if format_spec:
|
| 187 |
+
_type = format_spec[-1].lower()
|
| 188 |
+
try:
|
| 189 |
+
charset = {'a': self.ASCII, 'u': self.UTF, 'b': self.BLANK}[_type]
|
| 190 |
+
except KeyError:
|
| 191 |
+
charset = self.charset
|
| 192 |
+
else:
|
| 193 |
+
format_spec = format_spec[:-1]
|
| 194 |
+
if format_spec:
|
| 195 |
+
N_BARS = int(format_spec)
|
| 196 |
+
if N_BARS < 0:
|
| 197 |
+
N_BARS += self.default_len
|
| 198 |
+
else:
|
| 199 |
+
N_BARS = self.default_len
|
| 200 |
+
else:
|
| 201 |
+
charset = self.charset
|
| 202 |
+
N_BARS = self.default_len
|
| 203 |
+
|
| 204 |
+
nsyms = len(charset) - 1
|
| 205 |
+
bar_length, frac_bar_length = divmod(int(self.frac * N_BARS * nsyms), nsyms)
|
| 206 |
+
|
| 207 |
+
res = charset[-1] * bar_length
|
| 208 |
+
if bar_length < N_BARS: # whitespace padding
|
| 209 |
+
res = res + charset[frac_bar_length] + charset[0] * (N_BARS - bar_length - 1)
|
| 210 |
+
return self.colour + res + self.COLOUR_RESET if self.colour else res
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class EMA:
|
| 214 |
+
"""
|
| 215 |
+
Exponential moving average: smoothing to give progressively lower
|
| 216 |
+
weights to older values.
|
| 217 |
+
|
| 218 |
+
Parameters
|
| 219 |
+
----------
|
| 220 |
+
smoothing : float, optional
|
| 221 |
+
Smoothing factor in range [0, 1], [default: 0.3].
|
| 222 |
+
Increase to give more weight to recent values.
|
| 223 |
+
Ranges from 0 (yields old value) to 1 (yields new value).
|
| 224 |
+
"""
|
| 225 |
+
def __init__(self, smoothing=0.3):
|
| 226 |
+
self.alpha = smoothing
|
| 227 |
+
self.last = 0
|
| 228 |
+
self.calls = 0
|
| 229 |
+
|
| 230 |
+
def __call__(self, x=None):
|
| 231 |
+
"""
|
| 232 |
+
Parameters
|
| 233 |
+
----------
|
| 234 |
+
x : float
|
| 235 |
+
New value to include in EMA.
|
| 236 |
+
"""
|
| 237 |
+
beta = 1 - self.alpha
|
| 238 |
+
if x is not None:
|
| 239 |
+
self.last = self.alpha * x + beta * self.last
|
| 240 |
+
self.calls += 1
|
| 241 |
+
return self.last / (1 - beta ** self.calls) if self.calls else self.last
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class tqdm(Comparable):
|
| 245 |
+
"""
|
| 246 |
+
Decorate an iterable object, returning an iterator which acts exactly
|
| 247 |
+
like the original iterable, but prints a dynamically updating
|
| 248 |
+
progressbar every time a value is requested.
|
| 249 |
+
|
| 250 |
+
Parameters
|
| 251 |
+
----------
|
| 252 |
+
iterable : iterable, optional
|
| 253 |
+
Iterable to decorate with a progressbar.
|
| 254 |
+
Leave blank to manually manage the updates.
|
| 255 |
+
desc : str, optional
|
| 256 |
+
Prefix for the progressbar.
|
| 257 |
+
total : int or float, optional
|
| 258 |
+
The number of expected iterations. If unspecified,
|
| 259 |
+
len(iterable) is used if possible. If float("inf") or as a last
|
| 260 |
+
resort, only basic progress statistics are displayed
|
| 261 |
+
(no ETA, no progressbar).
|
| 262 |
+
If `gui` is True and this parameter needs subsequent updating,
|
| 263 |
+
specify an initial arbitrary large positive number,
|
| 264 |
+
e.g. 9e9.
|
| 265 |
+
leave : bool, optional
|
| 266 |
+
If [default: True], keeps all traces of the progressbar
|
| 267 |
+
upon termination of iteration.
|
| 268 |
+
If `None`, will leave only if `position` is `0`.
|
| 269 |
+
file : `io.TextIOWrapper` or `io.StringIO`, optional
|
| 270 |
+
Specifies where to output the progress messages
|
| 271 |
+
(default: sys.stderr). Uses `file.write(str)` and `file.flush()`
|
| 272 |
+
methods. For encoding, see `write_bytes`.
|
| 273 |
+
ncols : int, optional
|
| 274 |
+
The width of the entire output message. If specified,
|
| 275 |
+
dynamically resizes the progressbar to stay within this bound.
|
| 276 |
+
If unspecified, attempts to use environment width. The
|
| 277 |
+
fallback is a meter width of 10 and no limit for the counter and
|
| 278 |
+
statistics. If 0, will not print any meter (only stats).
|
| 279 |
+
mininterval : float, optional
|
| 280 |
+
Minimum progress display update interval [default: 0.1] seconds.
|
| 281 |
+
maxinterval : float, optional
|
| 282 |
+
Maximum progress display update interval [default: 10] seconds.
|
| 283 |
+
Automatically adjusts `miniters` to correspond to `mininterval`
|
| 284 |
+
after long display update lag. Only works if `dynamic_miniters`
|
| 285 |
+
or monitor thread is enabled.
|
| 286 |
+
miniters : int or float, optional
|
| 287 |
+
Minimum progress display update interval, in iterations.
|
| 288 |
+
If 0 and `dynamic_miniters`, will automatically adjust to equal
|
| 289 |
+
`mininterval` (more CPU efficient, good for tight loops).
|
| 290 |
+
If > 0, will skip display of specified number of iterations.
|
| 291 |
+
Tweak this and `mininterval` to get very efficient loops.
|
| 292 |
+
If your progress is erratic with both fast and slow iterations
|
| 293 |
+
(network, skipping items, etc) you should set miniters=1.
|
| 294 |
+
ascii : bool or str, optional
|
| 295 |
+
If unspecified or False, use unicode (smooth blocks) to fill
|
| 296 |
+
the meter. The fallback is to use ASCII characters " 123456789#".
|
| 297 |
+
disable : bool, optional
|
| 298 |
+
Whether to disable the entire progressbar wrapper
|
| 299 |
+
[default: False]. If set to None, disable on non-TTY.
|
| 300 |
+
unit : str, optional
|
| 301 |
+
String that will be used to define the unit of each iteration
|
| 302 |
+
[default: it].
|
| 303 |
+
unit_scale : bool or int or float, optional
|
| 304 |
+
If 1 or True, the number of iterations will be reduced/scaled
|
| 305 |
+
automatically and a metric prefix following the
|
| 306 |
+
International System of Units standard will be added
|
| 307 |
+
(kilo, mega, etc.) [default: False]. If any other non-zero
|
| 308 |
+
number, will scale `total` and `n`.
|
| 309 |
+
dynamic_ncols : bool, optional
|
| 310 |
+
If set, constantly alters `ncols` and `nrows` to the
|
| 311 |
+
environment (allowing for window resizes) [default: False].
|
| 312 |
+
smoothing : float, optional
|
| 313 |
+
Exponential moving average smoothing factor for speed estimates
|
| 314 |
+
(ignored in GUI mode). Ranges from 0 (average speed) to 1
|
| 315 |
+
(current/instantaneous speed) [default: 0.3].
|
| 316 |
+
bar_format : str, optional
|
| 317 |
+
Specify a custom bar string formatting. May impact performance.
|
| 318 |
+
[default: '{l_bar}{bar}{r_bar}'], where
|
| 319 |
+
l_bar='{desc}: {percentage:3.0f}%|' and
|
| 320 |
+
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
|
| 321 |
+
'{rate_fmt}{postfix}]'
|
| 322 |
+
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
|
| 323 |
+
percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
|
| 324 |
+
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
|
| 325 |
+
rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
| 326 |
+
remaining, remaining_s, eta.
|
| 327 |
+
Note that a trailing ": " is automatically removed after {desc}
|
| 328 |
+
if the latter is empty.
|
| 329 |
+
initial : int or float, optional
|
| 330 |
+
The initial counter value. Useful when restarting a progress
|
| 331 |
+
bar [default: 0]. If using float, consider specifying `{n:.3f}`
|
| 332 |
+
or similar in `bar_format`, or specifying `unit_scale`.
|
| 333 |
+
position : int, optional
|
| 334 |
+
Specify the line offset to print this bar (starting from 0)
|
| 335 |
+
Automatic if unspecified.
|
| 336 |
+
Useful to manage multiple bars at once (eg, from threads).
|
| 337 |
+
postfix : dict or *, optional
|
| 338 |
+
Specify additional stats to display at the end of the bar.
|
| 339 |
+
Calls `set_postfix(**postfix)` if possible (dict).
|
| 340 |
+
unit_divisor : float, optional
|
| 341 |
+
[default: 1000], ignored unless `unit_scale` is True.
|
| 342 |
+
write_bytes : bool, optional
|
| 343 |
+
Whether to write bytes. If (default: False) will write unicode.
|
| 344 |
+
lock_args : tuple, optional
|
| 345 |
+
Passed to `refresh` for intermediate output
|
| 346 |
+
(initialisation, iterating, and updating).
|
| 347 |
+
nrows : int, optional
|
| 348 |
+
The screen height. If specified, hides nested bars outside this
|
| 349 |
+
bound. If unspecified, attempts to use environment height.
|
| 350 |
+
The fallback is 20.
|
| 351 |
+
colour : str, optional
|
| 352 |
+
Bar colour (e.g. 'green', '#00ff00').
|
| 353 |
+
delay : float, optional
|
| 354 |
+
Don't display until [default: 0] seconds have elapsed.
|
| 355 |
+
gui : bool, optional
|
| 356 |
+
WARNING: internal parameter - do not use.
|
| 357 |
+
Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
|
| 358 |
+
matplotlib animations for a graphical output [default: False].
|
| 359 |
+
|
| 360 |
+
Returns
|
| 361 |
+
-------
|
| 362 |
+
out : decorated iterator.
|
| 363 |
+
"""
|
| 364 |
+
|
| 365 |
+
monitor_interval = 10 # set to 0 to disable the thread
|
| 366 |
+
monitor = None
|
| 367 |
+
_instances = WeakSet()
|
| 368 |
+
|
| 369 |
+
@staticmethod
|
| 370 |
+
def format_sizeof(num, suffix='', divisor=1000):
|
| 371 |
+
"""
|
| 372 |
+
Formats a number (greater than unity) with SI Order of Magnitude
|
| 373 |
+
prefixes.
|
| 374 |
+
|
| 375 |
+
Parameters
|
| 376 |
+
----------
|
| 377 |
+
num : float
|
| 378 |
+
Number ( >= 1) to format.
|
| 379 |
+
suffix : str, optional
|
| 380 |
+
Post-postfix [default: ''].
|
| 381 |
+
divisor : float, optional
|
| 382 |
+
Divisor between prefixes [default: 1000].
|
| 383 |
+
|
| 384 |
+
Returns
|
| 385 |
+
-------
|
| 386 |
+
out : str
|
| 387 |
+
Number with Order of Magnitude SI unit postfix.
|
| 388 |
+
"""
|
| 389 |
+
for unit in ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z']:
|
| 390 |
+
if abs(num) < 999.5:
|
| 391 |
+
if abs(num) < 99.95:
|
| 392 |
+
if abs(num) < 9.995:
|
| 393 |
+
return f'{num:1.2f}{unit}{suffix}'
|
| 394 |
+
return f'{num:2.1f}{unit}{suffix}'
|
| 395 |
+
return f'{num:3.0f}{unit}{suffix}'
|
| 396 |
+
num /= divisor
|
| 397 |
+
return f'{num:3.1f}Y{suffix}'
|
| 398 |
+
|
| 399 |
+
@staticmethod
|
| 400 |
+
def format_interval(t):
|
| 401 |
+
"""
|
| 402 |
+
Formats a number of seconds as a clock time, [H:]MM:SS
|
| 403 |
+
|
| 404 |
+
Parameters
|
| 405 |
+
----------
|
| 406 |
+
t : int
|
| 407 |
+
Number of seconds.
|
| 408 |
+
|
| 409 |
+
Returns
|
| 410 |
+
-------
|
| 411 |
+
out : str
|
| 412 |
+
[H:]MM:SS
|
| 413 |
+
"""
|
| 414 |
+
sign = '-' if t < 0 else ''
|
| 415 |
+
mins, s = divmod(abs(int(t)), 60)
|
| 416 |
+
h, m = divmod(mins, 60)
|
| 417 |
+
return f'{sign}{h:d}:{m:02d}:{s:02d}' if h else f'{sign}{m:02d}:{s:02d}'
|
| 418 |
+
|
| 419 |
+
@staticmethod
|
| 420 |
+
def format_num(n):
|
| 421 |
+
"""
|
| 422 |
+
Intelligent scientific notation (.3g).
|
| 423 |
+
|
| 424 |
+
Parameters
|
| 425 |
+
----------
|
| 426 |
+
n : int or float or Numeric
|
| 427 |
+
A Number.
|
| 428 |
+
|
| 429 |
+
Returns
|
| 430 |
+
-------
|
| 431 |
+
out : str
|
| 432 |
+
Formatted number.
|
| 433 |
+
"""
|
| 434 |
+
f = f'{n:.3g}'.replace('e+0', 'e+').replace('e-0', 'e-')
|
| 435 |
+
n = str(n)
|
| 436 |
+
return f if len(f) < len(n) else n
|
| 437 |
+
|
| 438 |
+
@staticmethod
|
| 439 |
+
def status_printer(file):
|
| 440 |
+
"""
|
| 441 |
+
Manage the printing and in-place updating of a line of characters.
|
| 442 |
+
Note that if the string is longer than a line, then in-place
|
| 443 |
+
updating may not work (it will print a new line at each refresh).
|
| 444 |
+
"""
|
| 445 |
+
fp = file
|
| 446 |
+
fp_flush = getattr(fp, 'flush', lambda: None) # pragma: no cover
|
| 447 |
+
if fp in (sys.stderr, sys.stdout):
|
| 448 |
+
getattr(sys.stderr, 'flush', lambda: None)()
|
| 449 |
+
getattr(sys.stdout, 'flush', lambda: None)()
|
| 450 |
+
|
| 451 |
+
def fp_write(s):
|
| 452 |
+
fp.write(str(s))
|
| 453 |
+
fp_flush()
|
| 454 |
+
|
| 455 |
+
last_len = [0]
|
| 456 |
+
|
| 457 |
+
def print_status(s):
|
| 458 |
+
len_s = disp_len(s)
|
| 459 |
+
fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0)))
|
| 460 |
+
last_len[0] = len_s
|
| 461 |
+
|
| 462 |
+
return print_status
|
| 463 |
+
|
| 464 |
+
@staticmethod
|
| 465 |
+
def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it',
|
| 466 |
+
unit_scale=False, rate=None, bar_format=None, postfix=None,
|
| 467 |
+
unit_divisor=1000, initial=0, colour=None, **extra_kwargs):
|
| 468 |
+
"""
|
| 469 |
+
Return a string-based progress bar given some parameters
|
| 470 |
+
|
| 471 |
+
Parameters
|
| 472 |
+
----------
|
| 473 |
+
n : int or float
|
| 474 |
+
Number of finished iterations.
|
| 475 |
+
total : int or float
|
| 476 |
+
The expected total number of iterations. If meaningless (None),
|
| 477 |
+
only basic progress statistics are displayed (no ETA).
|
| 478 |
+
elapsed : float
|
| 479 |
+
Number of seconds passed since start.
|
| 480 |
+
ncols : int, optional
|
| 481 |
+
The width of the entire output message. If specified,
|
| 482 |
+
dynamically resizes `{bar}` to stay within this bound
|
| 483 |
+
[default: None]. If `0`, will not print any bar (only stats).
|
| 484 |
+
The fallback is `{bar:10}`.
|
| 485 |
+
prefix : str, optional
|
| 486 |
+
Prefix message (included in total width) [default: ''].
|
| 487 |
+
Use as {desc} in bar_format string.
|
| 488 |
+
ascii : bool, optional or str, optional
|
| 489 |
+
If not set, use unicode (smooth blocks) to fill the meter
|
| 490 |
+
[default: False]. The fallback is to use ASCII characters
|
| 491 |
+
" 123456789#".
|
| 492 |
+
unit : str, optional
|
| 493 |
+
The iteration unit [default: 'it'].
|
| 494 |
+
unit_scale : bool or int or float, optional
|
| 495 |
+
If 1 or True, the number of iterations will be printed with an
|
| 496 |
+
appropriate SI metric prefix (k = 10^3, M = 10^6, etc.)
|
| 497 |
+
[default: False]. If any other non-zero number, will scale
|
| 498 |
+
`total` and `n`.
|
| 499 |
+
rate : float, optional
|
| 500 |
+
Manual override for iteration rate.
|
| 501 |
+
If [default: None], uses n/elapsed.
|
| 502 |
+
bar_format : str, optional
|
| 503 |
+
Specify a custom bar string formatting. May impact performance.
|
| 504 |
+
[default: '{l_bar}{bar}{r_bar}'], where
|
| 505 |
+
l_bar='{desc}: {percentage:3.0f}%|' and
|
| 506 |
+
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
|
| 507 |
+
'{rate_fmt}{postfix}]'
|
| 508 |
+
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
|
| 509 |
+
percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
|
| 510 |
+
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
|
| 511 |
+
rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
| 512 |
+
remaining, remaining_s, eta.
|
| 513 |
+
Note that a trailing ": " is automatically removed after {desc}
|
| 514 |
+
if the latter is empty.
|
| 515 |
+
postfix : *, optional
|
| 516 |
+
Similar to `prefix`, but placed at the end
|
| 517 |
+
(e.g. for additional stats).
|
| 518 |
+
Note: postfix is usually a string (not a dict) for this method,
|
| 519 |
+
and will if possible be set to postfix = ', ' + postfix.
|
| 520 |
+
However other types are supported (#382).
|
| 521 |
+
unit_divisor : float, optional
|
| 522 |
+
[default: 1000], ignored unless `unit_scale` is True.
|
| 523 |
+
initial : int or float, optional
|
| 524 |
+
The initial counter value [default: 0].
|
| 525 |
+
colour : str, optional
|
| 526 |
+
Bar colour (e.g. 'green', '#00ff00').
|
| 527 |
+
|
| 528 |
+
Returns
|
| 529 |
+
-------
|
| 530 |
+
out : Formatted meter and stats, ready to display.
|
| 531 |
+
"""
|
| 532 |
+
|
| 533 |
+
# sanity check: total
|
| 534 |
+
if total and n >= (total + 0.5): # allow float imprecision (#849)
|
| 535 |
+
total = None
|
| 536 |
+
|
| 537 |
+
# apply custom scale if necessary
|
| 538 |
+
if unit_scale and unit_scale not in (True, 1):
|
| 539 |
+
if total:
|
| 540 |
+
total *= unit_scale
|
| 541 |
+
n *= unit_scale
|
| 542 |
+
if rate:
|
| 543 |
+
rate *= unit_scale # by default rate = self.avg_dn / self.avg_dt
|
| 544 |
+
unit_scale = False
|
| 545 |
+
|
| 546 |
+
elapsed_str = tqdm.format_interval(elapsed)
|
| 547 |
+
|
| 548 |
+
# if unspecified, attempt to use rate = average speed
|
| 549 |
+
# (we allow manual override since predicting time is an arcane art)
|
| 550 |
+
if rate is None and elapsed:
|
| 551 |
+
rate = (n - initial) / elapsed
|
| 552 |
+
inv_rate = 1 / rate if rate else None
|
| 553 |
+
format_sizeof = tqdm.format_sizeof
|
| 554 |
+
rate_noinv_fmt = ((format_sizeof(rate) if unit_scale else f'{rate:5.2f}')
|
| 555 |
+
if rate else '?') + unit + '/s'
|
| 556 |
+
rate_inv_fmt = (
|
| 557 |
+
(format_sizeof(inv_rate) if unit_scale else f'{inv_rate:5.2f}')
|
| 558 |
+
if inv_rate else '?') + 's/' + unit
|
| 559 |
+
rate_fmt = rate_inv_fmt if inv_rate and inv_rate > 1 else rate_noinv_fmt
|
| 560 |
+
|
| 561 |
+
if unit_scale:
|
| 562 |
+
n_fmt = format_sizeof(n, divisor=unit_divisor)
|
| 563 |
+
total_fmt = format_sizeof(total, divisor=unit_divisor) if total is not None else '?'
|
| 564 |
+
else:
|
| 565 |
+
n_fmt = str(n)
|
| 566 |
+
total_fmt = str(total) if total is not None else '?'
|
| 567 |
+
|
| 568 |
+
try:
|
| 569 |
+
postfix = ', ' + postfix if postfix else ''
|
| 570 |
+
except TypeError:
|
| 571 |
+
pass
|
| 572 |
+
|
| 573 |
+
remaining = (total - n) / rate if rate and total else 0
|
| 574 |
+
remaining_str = tqdm.format_interval(remaining) if rate else '?'
|
| 575 |
+
try:
|
| 576 |
+
eta_dt = (datetime.now() + timedelta(seconds=remaining)
|
| 577 |
+
if rate and total else datetime.fromtimestamp(0, timezone.utc))
|
| 578 |
+
except OverflowError:
|
| 579 |
+
eta_dt = datetime.max
|
| 580 |
+
|
| 581 |
+
# format the stats displayed to the left and right sides of the bar
|
| 582 |
+
if prefix:
|
| 583 |
+
# old prefix setup work around
|
| 584 |
+
bool_prefix_colon_already = (prefix[-2:] == ": ")
|
| 585 |
+
l_bar = prefix if bool_prefix_colon_already else prefix + ": "
|
| 586 |
+
else:
|
| 587 |
+
l_bar = ''
|
| 588 |
+
|
| 589 |
+
r_bar = f'| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}{postfix}]'
|
| 590 |
+
|
| 591 |
+
# Custom bar formatting
|
| 592 |
+
# Populate a dict with all available progress indicators
|
| 593 |
+
format_dict = {
|
| 594 |
+
# slight extension of self.format_dict
|
| 595 |
+
'n': n, 'n_fmt': n_fmt, 'total': total, 'total_fmt': total_fmt,
|
| 596 |
+
'elapsed': elapsed_str, 'elapsed_s': elapsed,
|
| 597 |
+
'ncols': ncols, 'desc': prefix or '', 'unit': unit,
|
| 598 |
+
'rate': inv_rate if inv_rate and inv_rate > 1 else rate,
|
| 599 |
+
'rate_fmt': rate_fmt, 'rate_noinv': rate,
|
| 600 |
+
'rate_noinv_fmt': rate_noinv_fmt, 'rate_inv': inv_rate,
|
| 601 |
+
'rate_inv_fmt': rate_inv_fmt,
|
| 602 |
+
'postfix': postfix, 'unit_divisor': unit_divisor,
|
| 603 |
+
'colour': colour,
|
| 604 |
+
# plus more useful definitions
|
| 605 |
+
'remaining': remaining_str, 'remaining_s': remaining,
|
| 606 |
+
'l_bar': l_bar, 'r_bar': r_bar, 'eta': eta_dt,
|
| 607 |
+
**extra_kwargs}
|
| 608 |
+
|
| 609 |
+
# total is known: we can predict some stats
|
| 610 |
+
if total:
|
| 611 |
+
# fractional and percentage progress
|
| 612 |
+
frac = n / total
|
| 613 |
+
percentage = frac * 100
|
| 614 |
+
|
| 615 |
+
l_bar += f'{percentage:3.0f}%|'
|
| 616 |
+
|
| 617 |
+
if ncols == 0:
|
| 618 |
+
return l_bar[:-1] + r_bar[1:]
|
| 619 |
+
|
| 620 |
+
format_dict.update(l_bar=l_bar)
|
| 621 |
+
if bar_format:
|
| 622 |
+
format_dict.update(percentage=percentage)
|
| 623 |
+
|
| 624 |
+
# auto-remove colon for empty `{desc}`
|
| 625 |
+
if not prefix:
|
| 626 |
+
bar_format = bar_format.replace("{desc}: ", '')
|
| 627 |
+
else:
|
| 628 |
+
bar_format = "{l_bar}{bar}{r_bar}"
|
| 629 |
+
|
| 630 |
+
full_bar = FormatReplace()
|
| 631 |
+
nobar = bar_format.format(bar=full_bar, **format_dict)
|
| 632 |
+
if not full_bar.format_called:
|
| 633 |
+
return nobar # no `{bar}`; nothing else to do
|
| 634 |
+
|
| 635 |
+
# Formatting progress bar space available for bar's display
|
| 636 |
+
full_bar = Bar(frac,
|
| 637 |
+
max(1, ncols - disp_len(nobar)) if ncols else 10,
|
| 638 |
+
charset=Bar.ASCII if ascii is True else ascii or Bar.UTF,
|
| 639 |
+
colour=colour)
|
| 640 |
+
if not _is_ascii(full_bar.charset) and _is_ascii(bar_format):
|
| 641 |
+
bar_format = str(bar_format)
|
| 642 |
+
res = bar_format.format(bar=full_bar, **format_dict)
|
| 643 |
+
return disp_trim(res, ncols) if ncols else res
|
| 644 |
+
|
| 645 |
+
elif bar_format:
|
| 646 |
+
# user-specified bar_format but no total
|
| 647 |
+
l_bar += '|'
|
| 648 |
+
format_dict.update(l_bar=l_bar, percentage=0)
|
| 649 |
+
full_bar = FormatReplace()
|
| 650 |
+
nobar = bar_format.format(bar=full_bar, **format_dict)
|
| 651 |
+
if not full_bar.format_called:
|
| 652 |
+
return nobar
|
| 653 |
+
full_bar = Bar(0,
|
| 654 |
+
max(1, ncols - disp_len(nobar)) if ncols else 10,
|
| 655 |
+
charset=Bar.BLANK, colour=colour)
|
| 656 |
+
res = bar_format.format(bar=full_bar, **format_dict)
|
| 657 |
+
return disp_trim(res, ncols) if ncols else res
|
| 658 |
+
else:
|
| 659 |
+
# no total: no progressbar, ETA, just progress stats
|
| 660 |
+
return (f'{(prefix + ": ") if prefix else ""}'
|
| 661 |
+
f'{n_fmt}{unit} [{elapsed_str}, {rate_fmt}{postfix}]')
|
| 662 |
+
|
| 663 |
+
def __new__(cls, *_, **__):
|
| 664 |
+
instance = object.__new__(cls)
|
| 665 |
+
with cls.get_lock(): # also constructs lock if non-existent
|
| 666 |
+
cls._instances.add(instance)
|
| 667 |
+
# create monitoring thread
|
| 668 |
+
if cls.monitor_interval and (cls.monitor is None
|
| 669 |
+
or not cls.monitor.report()):
|
| 670 |
+
try:
|
| 671 |
+
cls.monitor = TMonitor(cls, cls.monitor_interval)
|
| 672 |
+
except Exception as e: # pragma: nocover
|
| 673 |
+
warn("tqdm:disabling monitor support"
|
| 674 |
+
" (monitor_interval = 0) due to:\n" + str(e),
|
| 675 |
+
TqdmMonitorWarning, stacklevel=2)
|
| 676 |
+
cls.monitor_interval = 0
|
| 677 |
+
return instance
|
| 678 |
+
|
| 679 |
+
@classmethod
|
| 680 |
+
def _get_free_pos(cls, instance=None):
|
| 681 |
+
"""Skips specified instance."""
|
| 682 |
+
positions = {abs(inst.pos) for inst in cls._instances
|
| 683 |
+
if inst is not instance and hasattr(inst, "pos")}
|
| 684 |
+
return min(set(range(len(positions) + 1)).difference(positions))
|
| 685 |
+
|
| 686 |
+
@classmethod
|
| 687 |
+
def _decr_instances(cls, instance):
|
| 688 |
+
"""
|
| 689 |
+
Remove from list and reposition another unfixed bar
|
| 690 |
+
to fill the new gap.
|
| 691 |
+
|
| 692 |
+
This means that by default (where all nested bars are unfixed),
|
| 693 |
+
order is not maintained but screen flicker/blank space is minimised.
|
| 694 |
+
(tqdm<=4.44.1 moved ALL subsequent unfixed bars up.)
|
| 695 |
+
"""
|
| 696 |
+
with cls._lock:
|
| 697 |
+
try:
|
| 698 |
+
cls._instances.remove(instance)
|
| 699 |
+
except KeyError:
|
| 700 |
+
# if not instance.gui: # pragma: no cover
|
| 701 |
+
# raise
|
| 702 |
+
pass # py2: maybe magically removed already
|
| 703 |
+
# else:
|
| 704 |
+
if not instance.gui:
|
| 705 |
+
last = (instance.nrows or 20) - 1
|
| 706 |
+
# find unfixed (`pos >= 0`) overflow (`pos >= nrows - 1`)
|
| 707 |
+
instances = list(filter(
|
| 708 |
+
lambda i: hasattr(i, "pos") and last <= i.pos,
|
| 709 |
+
cls._instances))
|
| 710 |
+
# set first found to current `pos`
|
| 711 |
+
if instances:
|
| 712 |
+
inst = min(instances, key=lambda i: i.pos)
|
| 713 |
+
inst.clear(nolock=True)
|
| 714 |
+
inst.pos = abs(instance.pos)
|
| 715 |
+
|
| 716 |
+
@classmethod
|
| 717 |
+
def write(cls, s, file=None, end="\n", nolock=False):
|
| 718 |
+
"""Print a message via tqdm (without overlap with bars)."""
|
| 719 |
+
fp = file if file is not None else sys.stdout
|
| 720 |
+
with cls.external_write_mode(file=file, nolock=nolock):
|
| 721 |
+
# Write the message
|
| 722 |
+
fp.write(s)
|
| 723 |
+
fp.write(end)
|
| 724 |
+
|
| 725 |
+
@classmethod
|
| 726 |
+
@contextmanager
|
| 727 |
+
def external_write_mode(cls, file=None, nolock=False):
|
| 728 |
+
"""
|
| 729 |
+
Disable tqdm within context and refresh tqdm when exits.
|
| 730 |
+
Useful when writing to standard output stream
|
| 731 |
+
"""
|
| 732 |
+
fp = file if file is not None else sys.stdout
|
| 733 |
+
|
| 734 |
+
try:
|
| 735 |
+
if not nolock:
|
| 736 |
+
cls.get_lock().acquire()
|
| 737 |
+
# Clear all bars
|
| 738 |
+
inst_cleared = []
|
| 739 |
+
for inst in getattr(cls, '_instances', []):
|
| 740 |
+
# Clear instance if in the target output file
|
| 741 |
+
# or if write output + tqdm output are both either
|
| 742 |
+
# sys.stdout or sys.stderr (because both are mixed in terminal)
|
| 743 |
+
if hasattr(inst, "start_t") and (inst.fp == fp or all(
|
| 744 |
+
f in (sys.stdout, sys.stderr) for f in (fp, inst.fp))):
|
| 745 |
+
inst.clear(nolock=True)
|
| 746 |
+
inst_cleared.append(inst)
|
| 747 |
+
yield
|
| 748 |
+
# Force refresh display of bars we cleared
|
| 749 |
+
for inst in inst_cleared:
|
| 750 |
+
inst.refresh(nolock=True)
|
| 751 |
+
finally:
|
| 752 |
+
if not nolock:
|
| 753 |
+
cls._lock.release()
|
| 754 |
+
|
| 755 |
+
@classmethod
|
| 756 |
+
def set_lock(cls, lock):
|
| 757 |
+
"""Set the global lock."""
|
| 758 |
+
cls._lock = lock
|
| 759 |
+
|
| 760 |
+
@classmethod
|
| 761 |
+
def get_lock(cls):
|
| 762 |
+
"""Get the global lock. Construct it if it does not exist."""
|
| 763 |
+
if not hasattr(cls, '_lock'):
|
| 764 |
+
cls._lock = TqdmDefaultWriteLock()
|
| 765 |
+
return cls._lock
|
| 766 |
+
|
| 767 |
+
@classmethod
|
| 768 |
+
def pandas(cls, **tqdm_kwargs):
|
| 769 |
+
"""
|
| 770 |
+
Registers the current `tqdm` class with
|
| 771 |
+
pandas.core.
|
| 772 |
+
( frame.DataFrame
|
| 773 |
+
| series.Series
|
| 774 |
+
| groupby.(generic.)DataFrameGroupBy
|
| 775 |
+
| groupby.(generic.)SeriesGroupBy
|
| 776 |
+
).progress_apply
|
| 777 |
+
|
| 778 |
+
A new instance will be created every time `progress_apply` is called,
|
| 779 |
+
and each instance will automatically `close()` upon completion.
|
| 780 |
+
|
| 781 |
+
Parameters
|
| 782 |
+
----------
|
| 783 |
+
tqdm_kwargs : arguments for the tqdm instance
|
| 784 |
+
|
| 785 |
+
Examples
|
| 786 |
+
--------
|
| 787 |
+
>>> import pandas as pd
|
| 788 |
+
>>> import numpy as np
|
| 789 |
+
>>> from tqdm import tqdm
|
| 790 |
+
>>> from tqdm.gui import tqdm as tqdm_gui
|
| 791 |
+
>>>
|
| 792 |
+
>>> df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
|
| 793 |
+
>>> tqdm.pandas(ncols=50) # can use tqdm_gui, optional kwargs, etc
|
| 794 |
+
>>> # Now you can use `progress_apply` instead of `apply`
|
| 795 |
+
>>> df.groupby(0).progress_apply(lambda x: x**2)
|
| 796 |
+
|
| 797 |
+
References
|
| 798 |
+
----------
|
| 799 |
+
<https://stackoverflow.com/questions/18603270/\
|
| 800 |
+
progress-indicator-during-pandas-operations-python>
|
| 801 |
+
"""
|
| 802 |
+
from warnings import catch_warnings, simplefilter
|
| 803 |
+
|
| 804 |
+
from pandas.core.frame import DataFrame
|
| 805 |
+
from pandas.core.series import Series
|
| 806 |
+
try:
|
| 807 |
+
with catch_warnings():
|
| 808 |
+
simplefilter("ignore", category=FutureWarning)
|
| 809 |
+
from pandas import Panel
|
| 810 |
+
except ImportError: # pandas>=1.2.0
|
| 811 |
+
Panel = None
|
| 812 |
+
Rolling, Expanding = None, None
|
| 813 |
+
try: # pandas>=1.0.0
|
| 814 |
+
from pandas.core.window.rolling import _Rolling_and_Expanding
|
| 815 |
+
except ImportError:
|
| 816 |
+
try: # pandas>=0.18.0
|
| 817 |
+
from pandas.core.window import _Rolling_and_Expanding
|
| 818 |
+
except ImportError: # pandas>=1.2.0
|
| 819 |
+
try: # pandas>=1.2.0
|
| 820 |
+
from pandas.core.window.expanding import Expanding
|
| 821 |
+
from pandas.core.window.rolling import Rolling
|
| 822 |
+
_Rolling_and_Expanding = Rolling, Expanding
|
| 823 |
+
except ImportError: # pragma: no cover
|
| 824 |
+
_Rolling_and_Expanding = None
|
| 825 |
+
try: # pandas>=0.25.0
|
| 826 |
+
from pandas.core.groupby.generic import SeriesGroupBy # , NDFrameGroupBy
|
| 827 |
+
from pandas.core.groupby.generic import DataFrameGroupBy
|
| 828 |
+
except ImportError: # pragma: no cover
|
| 829 |
+
try: # pandas>=0.23.0
|
| 830 |
+
from pandas.core.groupby.groupby import DataFrameGroupBy, SeriesGroupBy
|
| 831 |
+
except ImportError:
|
| 832 |
+
from pandas.core.groupby import DataFrameGroupBy, SeriesGroupBy
|
| 833 |
+
try: # pandas>=0.23.0
|
| 834 |
+
from pandas.core.groupby.groupby import GroupBy
|
| 835 |
+
except ImportError: # pragma: no cover
|
| 836 |
+
from pandas.core.groupby import GroupBy
|
| 837 |
+
|
| 838 |
+
try: # pandas>=0.23.0
|
| 839 |
+
from pandas.core.groupby.groupby import PanelGroupBy
|
| 840 |
+
except ImportError:
|
| 841 |
+
try:
|
| 842 |
+
from pandas.core.groupby import PanelGroupBy
|
| 843 |
+
except ImportError: # pandas>=0.25.0
|
| 844 |
+
PanelGroupBy = None
|
| 845 |
+
|
| 846 |
+
tqdm_kwargs = tqdm_kwargs.copy()
|
| 847 |
+
deprecated_t = [tqdm_kwargs.pop('deprecated_t', None)]
|
| 848 |
+
|
| 849 |
+
def inner_generator(df_function='apply'):
|
| 850 |
+
def inner(df, func, *args, **kwargs):
|
| 851 |
+
"""
|
| 852 |
+
Parameters
|
| 853 |
+
----------
|
| 854 |
+
df : (DataFrame|Series)[GroupBy]
|
| 855 |
+
Data (may be grouped).
|
| 856 |
+
func : function
|
| 857 |
+
To be applied on the (grouped) data.
|
| 858 |
+
**kwargs : optional
|
| 859 |
+
Transmitted to `df.apply()`.
|
| 860 |
+
"""
|
| 861 |
+
|
| 862 |
+
# Precompute total iterations
|
| 863 |
+
total = tqdm_kwargs.pop("total", getattr(df, 'ngroups', None))
|
| 864 |
+
if total is None: # not grouped
|
| 865 |
+
if df_function == 'applymap':
|
| 866 |
+
total = df.size
|
| 867 |
+
elif isinstance(df, Series):
|
| 868 |
+
total = len(df)
|
| 869 |
+
elif (_Rolling_and_Expanding is None or
|
| 870 |
+
not isinstance(df, _Rolling_and_Expanding)):
|
| 871 |
+
# DataFrame or Panel
|
| 872 |
+
axis = kwargs.get('axis', 0)
|
| 873 |
+
if axis == 'index':
|
| 874 |
+
axis = 0
|
| 875 |
+
elif axis == 'columns':
|
| 876 |
+
axis = 1
|
| 877 |
+
# when axis=0, total is shape[axis1]
|
| 878 |
+
total = df.size // df.shape[axis]
|
| 879 |
+
|
| 880 |
+
# Init bar
|
| 881 |
+
if deprecated_t[0] is not None:
|
| 882 |
+
t = deprecated_t[0]
|
| 883 |
+
deprecated_t[0] = None
|
| 884 |
+
else:
|
| 885 |
+
t = cls(total=total, **tqdm_kwargs)
|
| 886 |
+
|
| 887 |
+
if len(args) > 0:
|
| 888 |
+
# *args intentionally not supported (see #244, #299)
|
| 889 |
+
TqdmDeprecationWarning(
|
| 890 |
+
"Except func, normal arguments are intentionally" +
|
| 891 |
+
" not supported by" +
|
| 892 |
+
" `(DataFrame|Series|GroupBy).progress_apply`." +
|
| 893 |
+
" Use keyword arguments instead.",
|
| 894 |
+
fp_write=getattr(t.fp, 'write', sys.stderr.write))
|
| 895 |
+
|
| 896 |
+
try: # pandas>=1.3.0,<3.0
|
| 897 |
+
from pandas.core.common import is_builtin_func
|
| 898 |
+
except ImportError: # pandas<1.3.0
|
| 899 |
+
is_builtin_func = getattr(df, '_is_builtin_func', lambda f: f)
|
| 900 |
+
try:
|
| 901 |
+
func = is_builtin_func(func)
|
| 902 |
+
except TypeError:
|
| 903 |
+
pass
|
| 904 |
+
|
| 905 |
+
# Define bar updating wrapper
|
| 906 |
+
def wrapper(*args, **kwargs):
|
| 907 |
+
# update tbar correctly
|
| 908 |
+
# it seems `pandas apply` calls `func` twice
|
| 909 |
+
# on the first column/row to decide whether it can
|
| 910 |
+
# take a fast or slow code path; so stop when t.total==t.n
|
| 911 |
+
t.update(n=1 if not t.total or t.n < t.total else 0)
|
| 912 |
+
return func(*args, **kwargs)
|
| 913 |
+
|
| 914 |
+
# Apply the provided function (in **kwargs)
|
| 915 |
+
# on the df using our wrapper (which provides bar updating)
|
| 916 |
+
try:
|
| 917 |
+
return getattr(df, df_function)(wrapper, **kwargs)
|
| 918 |
+
finally:
|
| 919 |
+
t.close()
|
| 920 |
+
|
| 921 |
+
return inner
|
| 922 |
+
|
| 923 |
+
# Monkeypatch pandas to provide easy methods
|
| 924 |
+
# Enable custom tqdm progress in pandas!
|
| 925 |
+
Series.progress_apply = inner_generator()
|
| 926 |
+
SeriesGroupBy.progress_apply = inner_generator()
|
| 927 |
+
Series.progress_map = inner_generator('map')
|
| 928 |
+
SeriesGroupBy.progress_map = inner_generator('map')
|
| 929 |
+
|
| 930 |
+
DataFrame.progress_apply = inner_generator()
|
| 931 |
+
DataFrameGroupBy.progress_apply = inner_generator()
|
| 932 |
+
DataFrame.progress_applymap = inner_generator('applymap')
|
| 933 |
+
DataFrame.progress_map = inner_generator('map')
|
| 934 |
+
DataFrameGroupBy.progress_map = inner_generator('map')
|
| 935 |
+
|
| 936 |
+
if Panel is not None:
|
| 937 |
+
Panel.progress_apply = inner_generator()
|
| 938 |
+
if PanelGroupBy is not None:
|
| 939 |
+
PanelGroupBy.progress_apply = inner_generator()
|
| 940 |
+
|
| 941 |
+
GroupBy.progress_apply = inner_generator()
|
| 942 |
+
GroupBy.progress_aggregate = inner_generator('aggregate')
|
| 943 |
+
GroupBy.progress_transform = inner_generator('transform')
|
| 944 |
+
|
| 945 |
+
if Rolling is not None and Expanding is not None:
|
| 946 |
+
Rolling.progress_apply = inner_generator()
|
| 947 |
+
Expanding.progress_apply = inner_generator()
|
| 948 |
+
elif _Rolling_and_Expanding is not None:
|
| 949 |
+
_Rolling_and_Expanding.progress_apply = inner_generator()
|
| 950 |
+
|
| 951 |
+
# override defaults via env vars
|
| 952 |
+
@envwrap("TQDM_", is_method=True, types={'total': float, 'ncols': int, 'miniters': float,
|
| 953 |
+
'position': int, 'nrows': int})
|
| 954 |
+
def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
|
| 955 |
+
ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None,
|
| 956 |
+
ascii=None, disable=False, unit='it', unit_scale=False,
|
| 957 |
+
dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0,
|
| 958 |
+
position=None, postfix=None, unit_divisor=1000, write_bytes=False,
|
| 959 |
+
lock_args=None, nrows=None, colour=None, delay=0.0, gui=False,
|
| 960 |
+
**kwargs):
|
| 961 |
+
"""see tqdm.tqdm for arguments"""
|
| 962 |
+
if file is None:
|
| 963 |
+
file = sys.stderr
|
| 964 |
+
|
| 965 |
+
if write_bytes:
|
| 966 |
+
# Despite coercing unicode into bytes, py2 sys.std* streams
|
| 967 |
+
# should have bytes written to them.
|
| 968 |
+
file = SimpleTextIOWrapper(
|
| 969 |
+
file, encoding=getattr(file, 'encoding', None) or 'utf-8')
|
| 970 |
+
|
| 971 |
+
file = DisableOnWriteError(file, tqdm_instance=self)
|
| 972 |
+
|
| 973 |
+
if disable is None and hasattr(file, "isatty") and not file.isatty():
|
| 974 |
+
disable = True
|
| 975 |
+
|
| 976 |
+
if total is None and iterable is not None:
|
| 977 |
+
try:
|
| 978 |
+
total = len(iterable)
|
| 979 |
+
except (TypeError, AttributeError):
|
| 980 |
+
total = None
|
| 981 |
+
if total == float("inf"):
|
| 982 |
+
# Infinite iterations, behave same as unknown
|
| 983 |
+
total = None
|
| 984 |
+
|
| 985 |
+
if disable:
|
| 986 |
+
self.iterable = iterable
|
| 987 |
+
self.disable = disable
|
| 988 |
+
with self._lock:
|
| 989 |
+
self.pos = self._get_free_pos(self)
|
| 990 |
+
self._instances.remove(self)
|
| 991 |
+
self.n = initial
|
| 992 |
+
self.total = total
|
| 993 |
+
self.leave = leave
|
| 994 |
+
return
|
| 995 |
+
|
| 996 |
+
if kwargs:
|
| 997 |
+
self.disable = True
|
| 998 |
+
with self._lock:
|
| 999 |
+
self.pos = self._get_free_pos(self)
|
| 1000 |
+
self._instances.remove(self)
|
| 1001 |
+
raise (
|
| 1002 |
+
TqdmDeprecationWarning(
|
| 1003 |
+
"`nested` is deprecated and automated.\n"
|
| 1004 |
+
"Use `position` instead for manual control.\n",
|
| 1005 |
+
fp_write=getattr(file, 'write', sys.stderr.write))
|
| 1006 |
+
if "nested" in kwargs else
|
| 1007 |
+
TqdmKeyError("Unknown argument(s): " + str(kwargs)))
|
| 1008 |
+
|
| 1009 |
+
# Preprocess the arguments
|
| 1010 |
+
if (
|
| 1011 |
+
(ncols is None or nrows is None) and (file in (sys.stderr, sys.stdout))
|
| 1012 |
+
) or dynamic_ncols: # pragma: no cover
|
| 1013 |
+
if dynamic_ncols:
|
| 1014 |
+
dynamic_ncols = _screen_shape_wrapper()
|
| 1015 |
+
if dynamic_ncols:
|
| 1016 |
+
ncols, nrows = dynamic_ncols(file)
|
| 1017 |
+
else:
|
| 1018 |
+
_dynamic_ncols = _screen_shape_wrapper()
|
| 1019 |
+
if _dynamic_ncols:
|
| 1020 |
+
_ncols, _nrows = _dynamic_ncols(file)
|
| 1021 |
+
if ncols is None:
|
| 1022 |
+
ncols = _ncols
|
| 1023 |
+
if nrows is None:
|
| 1024 |
+
nrows = _nrows
|
| 1025 |
+
|
| 1026 |
+
if miniters is None:
|
| 1027 |
+
miniters = 0
|
| 1028 |
+
dynamic_miniters = True
|
| 1029 |
+
else:
|
| 1030 |
+
dynamic_miniters = False
|
| 1031 |
+
|
| 1032 |
+
if mininterval is None:
|
| 1033 |
+
mininterval = 0
|
| 1034 |
+
|
| 1035 |
+
if maxinterval is None:
|
| 1036 |
+
maxinterval = 0
|
| 1037 |
+
|
| 1038 |
+
if ascii is None:
|
| 1039 |
+
ascii = not _supports_unicode(file)
|
| 1040 |
+
|
| 1041 |
+
if bar_format and ascii is not True and not _is_ascii(ascii):
|
| 1042 |
+
# Convert bar format into unicode since terminal uses unicode
|
| 1043 |
+
bar_format = str(bar_format)
|
| 1044 |
+
|
| 1045 |
+
if smoothing is None:
|
| 1046 |
+
smoothing = 0
|
| 1047 |
+
|
| 1048 |
+
# Store the arguments
|
| 1049 |
+
self.iterable = iterable
|
| 1050 |
+
self.desc = desc or ''
|
| 1051 |
+
self.total = total
|
| 1052 |
+
self.leave = leave
|
| 1053 |
+
self.fp = file
|
| 1054 |
+
self.ncols = ncols
|
| 1055 |
+
self.nrows = nrows
|
| 1056 |
+
self.mininterval = mininterval
|
| 1057 |
+
self.maxinterval = maxinterval
|
| 1058 |
+
self.miniters = miniters
|
| 1059 |
+
self.dynamic_miniters = dynamic_miniters
|
| 1060 |
+
self.ascii = ascii
|
| 1061 |
+
self.disable = disable
|
| 1062 |
+
self.unit = unit
|
| 1063 |
+
self.unit_scale = unit_scale
|
| 1064 |
+
self.unit_divisor = unit_divisor
|
| 1065 |
+
self.initial = initial
|
| 1066 |
+
self.lock_args = lock_args
|
| 1067 |
+
self.delay = delay
|
| 1068 |
+
self.gui = gui
|
| 1069 |
+
self.dynamic_ncols = dynamic_ncols
|
| 1070 |
+
self.smoothing = smoothing
|
| 1071 |
+
self._ema_dn = EMA(smoothing)
|
| 1072 |
+
self._ema_dt = EMA(smoothing)
|
| 1073 |
+
self._ema_miniters = EMA(smoothing)
|
| 1074 |
+
self.bar_format = bar_format
|
| 1075 |
+
self.postfix = None
|
| 1076 |
+
self.colour = colour
|
| 1077 |
+
self._time = time
|
| 1078 |
+
if postfix:
|
| 1079 |
+
try:
|
| 1080 |
+
self.set_postfix(refresh=False, **postfix)
|
| 1081 |
+
except TypeError:
|
| 1082 |
+
self.postfix = postfix
|
| 1083 |
+
|
| 1084 |
+
# Init the iterations counters
|
| 1085 |
+
self.last_print_n = initial
|
| 1086 |
+
self.n = initial
|
| 1087 |
+
|
| 1088 |
+
# if nested, at initial sp() call we replace '\r' by '\n' to
|
| 1089 |
+
# not overwrite the outer progress bar
|
| 1090 |
+
with self._lock:
|
| 1091 |
+
# mark fixed positions as negative
|
| 1092 |
+
self.pos = self._get_free_pos(self) if position is None else -position
|
| 1093 |
+
|
| 1094 |
+
if not gui:
|
| 1095 |
+
# Initialize the screen printer
|
| 1096 |
+
self.sp = self.status_printer(self.fp)
|
| 1097 |
+
if delay <= 0:
|
| 1098 |
+
self.refresh(lock_args=self.lock_args)
|
| 1099 |
+
|
| 1100 |
+
# Init the time counter
|
| 1101 |
+
self.last_print_t = self._time()
|
| 1102 |
+
# NB: Avoid race conditions by setting start_t at the very end of init
|
| 1103 |
+
self.start_t = self.last_print_t
|
| 1104 |
+
|
| 1105 |
+
def __bool__(self):
|
| 1106 |
+
if self.total is not None:
|
| 1107 |
+
return self.total > 0
|
| 1108 |
+
if self.iterable is None:
|
| 1109 |
+
raise TypeError('bool() undefined when iterable == total == None')
|
| 1110 |
+
return bool(self.iterable)
|
| 1111 |
+
|
| 1112 |
+
def __len__(self):
|
| 1113 |
+
return (
|
| 1114 |
+
self.total if self.iterable is None
|
| 1115 |
+
else self.iterable.shape[0] if hasattr(self.iterable, "shape")
|
| 1116 |
+
else len(self.iterable) if hasattr(self.iterable, "__len__")
|
| 1117 |
+
else self.iterable.__length_hint__() if hasattr(self.iterable, "__length_hint__")
|
| 1118 |
+
else getattr(self, "total", None))
|
| 1119 |
+
|
| 1120 |
+
def __reversed__(self):
|
| 1121 |
+
try:
|
| 1122 |
+
orig = self.iterable
|
| 1123 |
+
except AttributeError:
|
| 1124 |
+
raise TypeError("'tqdm' object is not reversible")
|
| 1125 |
+
else:
|
| 1126 |
+
self.iterable = reversed(self.iterable)
|
| 1127 |
+
return self.__iter__()
|
| 1128 |
+
finally:
|
| 1129 |
+
self.iterable = orig
|
| 1130 |
+
|
| 1131 |
+
def __contains__(self, item):
|
| 1132 |
+
contains = getattr(self.iterable, '__contains__', None)
|
| 1133 |
+
return contains(item) if contains is not None else item in self.__iter__()
|
| 1134 |
+
|
| 1135 |
+
def __enter__(self):
|
| 1136 |
+
return self
|
| 1137 |
+
|
| 1138 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 1139 |
+
try:
|
| 1140 |
+
self.close()
|
| 1141 |
+
except AttributeError:
|
| 1142 |
+
# maybe eager thread cleanup upon external error
|
| 1143 |
+
if (exc_type, exc_value, traceback) == (None, None, None):
|
| 1144 |
+
raise
|
| 1145 |
+
warn("AttributeError ignored", TqdmWarning, stacklevel=2)
|
| 1146 |
+
|
| 1147 |
+
def __del__(self):
|
| 1148 |
+
self.close()
|
| 1149 |
+
|
| 1150 |
+
def __str__(self):
|
| 1151 |
+
return self.format_meter(**self.format_dict)
|
| 1152 |
+
|
| 1153 |
+
@property
|
| 1154 |
+
def _comparable(self):
|
| 1155 |
+
return abs(getattr(self, "pos", 1 << 31))
|
| 1156 |
+
|
| 1157 |
+
def __hash__(self):
|
| 1158 |
+
return id(self)
|
| 1159 |
+
|
| 1160 |
+
def __iter__(self):
|
| 1161 |
+
"""Backward-compatibility to use: for x in tqdm(iterable)"""
|
| 1162 |
+
|
| 1163 |
+
# Inlining instance variables as locals (speed optimisation)
|
| 1164 |
+
iterable = self.iterable
|
| 1165 |
+
|
| 1166 |
+
# If the bar is disabled, then just walk the iterable
|
| 1167 |
+
# (note: keep this check outside the loop for performance)
|
| 1168 |
+
if self.disable:
|
| 1169 |
+
for obj in iterable:
|
| 1170 |
+
yield obj
|
| 1171 |
+
return
|
| 1172 |
+
|
| 1173 |
+
mininterval = self.mininterval
|
| 1174 |
+
last_print_t = self.last_print_t
|
| 1175 |
+
last_print_n = self.last_print_n
|
| 1176 |
+
min_start_t = self.start_t + self.delay
|
| 1177 |
+
n = self.n
|
| 1178 |
+
time = self._time
|
| 1179 |
+
|
| 1180 |
+
try:
|
| 1181 |
+
for obj in iterable:
|
| 1182 |
+
yield obj
|
| 1183 |
+
# Update and possibly print the progressbar.
|
| 1184 |
+
# Note: does not call self.update(1) for speed optimisation.
|
| 1185 |
+
n += 1
|
| 1186 |
+
|
| 1187 |
+
if n - last_print_n >= self.miniters:
|
| 1188 |
+
cur_t = time()
|
| 1189 |
+
dt = cur_t - last_print_t
|
| 1190 |
+
if dt >= mininterval and cur_t >= min_start_t:
|
| 1191 |
+
self.update(n - last_print_n)
|
| 1192 |
+
last_print_n = self.last_print_n
|
| 1193 |
+
last_print_t = self.last_print_t
|
| 1194 |
+
finally:
|
| 1195 |
+
self.n = n
|
| 1196 |
+
self.close()
|
| 1197 |
+
|
| 1198 |
+
def update(self, n=1):
|
| 1199 |
+
"""
|
| 1200 |
+
Manually update the progress bar, useful for streams
|
| 1201 |
+
such as reading files.
|
| 1202 |
+
E.g.:
|
| 1203 |
+
>>> t = tqdm(total=filesize) # Initialise
|
| 1204 |
+
>>> for current_buffer in stream:
|
| 1205 |
+
... ...
|
| 1206 |
+
... t.update(len(current_buffer))
|
| 1207 |
+
>>> t.close()
|
| 1208 |
+
The last line is highly recommended, but possibly not necessary if
|
| 1209 |
+
`t.update()` will be called in such a way that `filesize` will be
|
| 1210 |
+
exactly reached and printed.
|
| 1211 |
+
|
| 1212 |
+
Parameters
|
| 1213 |
+
----------
|
| 1214 |
+
n : int or float, optional
|
| 1215 |
+
Increment to add to the internal counter of iterations
|
| 1216 |
+
[default: 1]. If using float, consider specifying `{n:.3f}`
|
| 1217 |
+
or similar in `bar_format`, or specifying `unit_scale`.
|
| 1218 |
+
|
| 1219 |
+
Returns
|
| 1220 |
+
-------
|
| 1221 |
+
out : bool or None
|
| 1222 |
+
True if a `display()` was triggered.
|
| 1223 |
+
"""
|
| 1224 |
+
if self.disable:
|
| 1225 |
+
return
|
| 1226 |
+
|
| 1227 |
+
if n < 0:
|
| 1228 |
+
self.last_print_n += n # for auto-refresh logic to work
|
| 1229 |
+
self.n += n
|
| 1230 |
+
|
| 1231 |
+
# check counter first to reduce calls to time()
|
| 1232 |
+
if self.n - self.last_print_n >= self.miniters:
|
| 1233 |
+
cur_t = self._time()
|
| 1234 |
+
dt = cur_t - self.last_print_t
|
| 1235 |
+
if dt >= self.mininterval and cur_t >= self.start_t + self.delay:
|
| 1236 |
+
cur_t = self._time()
|
| 1237 |
+
dn = self.n - self.last_print_n # >= n
|
| 1238 |
+
if self.smoothing and dt and dn:
|
| 1239 |
+
# EMA (not just overall average)
|
| 1240 |
+
self._ema_dn(dn)
|
| 1241 |
+
self._ema_dt(dt)
|
| 1242 |
+
self.refresh(lock_args=self.lock_args)
|
| 1243 |
+
if self.dynamic_miniters:
|
| 1244 |
+
# If no `miniters` was specified, adjust automatically to the
|
| 1245 |
+
# maximum iteration rate seen so far between two prints.
|
| 1246 |
+
# e.g.: After running `tqdm.update(5)`, subsequent
|
| 1247 |
+
# calls to `tqdm.update()` will only cause an update after
|
| 1248 |
+
# at least 5 more iterations.
|
| 1249 |
+
if self.maxinterval and dt >= self.maxinterval:
|
| 1250 |
+
self.miniters = dn * (self.mininterval or self.maxinterval) / dt
|
| 1251 |
+
elif self.smoothing:
|
| 1252 |
+
# EMA miniters update
|
| 1253 |
+
self.miniters = self._ema_miniters(
|
| 1254 |
+
dn * (self.mininterval / dt if self.mininterval and dt
|
| 1255 |
+
else 1))
|
| 1256 |
+
else:
|
| 1257 |
+
# max iters between two prints
|
| 1258 |
+
self.miniters = max(self.miniters, dn)
|
| 1259 |
+
|
| 1260 |
+
# Store old values for next call
|
| 1261 |
+
self.last_print_n = self.n
|
| 1262 |
+
self.last_print_t = cur_t
|
| 1263 |
+
return True
|
| 1264 |
+
|
| 1265 |
+
def close(self):
|
| 1266 |
+
"""Cleanup and (if leave=False) close the progressbar."""
|
| 1267 |
+
if self.disable:
|
| 1268 |
+
return
|
| 1269 |
+
|
| 1270 |
+
# Prevent multiple closures
|
| 1271 |
+
self.disable = True
|
| 1272 |
+
|
| 1273 |
+
# decrement instance pos and remove from internal set
|
| 1274 |
+
pos = abs(self.pos)
|
| 1275 |
+
self._decr_instances(self)
|
| 1276 |
+
|
| 1277 |
+
if self.last_print_t < self.start_t + self.delay:
|
| 1278 |
+
# haven't ever displayed; nothing to clear
|
| 1279 |
+
return
|
| 1280 |
+
|
| 1281 |
+
# GUI mode
|
| 1282 |
+
if getattr(self, 'sp', None) is None:
|
| 1283 |
+
return
|
| 1284 |
+
|
| 1285 |
+
# annoyingly, _supports_unicode isn't good enough
|
| 1286 |
+
def fp_write(s):
|
| 1287 |
+
self.fp.write(str(s))
|
| 1288 |
+
|
| 1289 |
+
try:
|
| 1290 |
+
fp_write('')
|
| 1291 |
+
except ValueError as e:
|
| 1292 |
+
if 'closed' in str(e):
|
| 1293 |
+
return
|
| 1294 |
+
raise # pragma: no cover
|
| 1295 |
+
|
| 1296 |
+
leave = pos == 0 if self.leave is None else self.leave
|
| 1297 |
+
|
| 1298 |
+
with self._lock:
|
| 1299 |
+
if leave:
|
| 1300 |
+
# stats for overall rate (no weighted average)
|
| 1301 |
+
self._ema_dt = lambda: None
|
| 1302 |
+
self.display(pos=0)
|
| 1303 |
+
fp_write('\n')
|
| 1304 |
+
else:
|
| 1305 |
+
# clear previous display
|
| 1306 |
+
if self.display(msg='', pos=pos) and not pos:
|
| 1307 |
+
fp_write('\r')
|
| 1308 |
+
|
| 1309 |
+
def clear(self, nolock=False):
|
| 1310 |
+
"""Clear current bar display."""
|
| 1311 |
+
if self.disable:
|
| 1312 |
+
return
|
| 1313 |
+
|
| 1314 |
+
if not nolock:
|
| 1315 |
+
self._lock.acquire()
|
| 1316 |
+
pos = abs(self.pos)
|
| 1317 |
+
if pos < (self.nrows or 20):
|
| 1318 |
+
self.moveto(pos)
|
| 1319 |
+
self.sp('')
|
| 1320 |
+
self.fp.write('\r') # place cursor back at the beginning of line
|
| 1321 |
+
self.moveto(-pos)
|
| 1322 |
+
if not nolock:
|
| 1323 |
+
self._lock.release()
|
| 1324 |
+
|
| 1325 |
+
def refresh(self, nolock=False, lock_args=None):
|
| 1326 |
+
"""
|
| 1327 |
+
Force refresh the display of this bar.
|
| 1328 |
+
|
| 1329 |
+
Parameters
|
| 1330 |
+
----------
|
| 1331 |
+
nolock : bool, optional
|
| 1332 |
+
If `True`, does not lock.
|
| 1333 |
+
If [default: `False`]: calls `acquire()` on internal lock.
|
| 1334 |
+
lock_args : tuple, optional
|
| 1335 |
+
Passed to internal lock's `acquire()`.
|
| 1336 |
+
If specified, will only `display()` if `acquire()` returns `True`.
|
| 1337 |
+
"""
|
| 1338 |
+
if self.disable:
|
| 1339 |
+
return
|
| 1340 |
+
|
| 1341 |
+
if not nolock:
|
| 1342 |
+
if lock_args:
|
| 1343 |
+
if not self._lock.acquire(*lock_args):
|
| 1344 |
+
return False
|
| 1345 |
+
else:
|
| 1346 |
+
self._lock.acquire()
|
| 1347 |
+
self.display()
|
| 1348 |
+
if not nolock:
|
| 1349 |
+
self._lock.release()
|
| 1350 |
+
return True
|
| 1351 |
+
|
| 1352 |
+
def unpause(self):
|
| 1353 |
+
"""Restart tqdm timer from last print time."""
|
| 1354 |
+
if self.disable:
|
| 1355 |
+
return
|
| 1356 |
+
cur_t = self._time()
|
| 1357 |
+
self.start_t += cur_t - self.last_print_t
|
| 1358 |
+
self.last_print_t = cur_t
|
| 1359 |
+
|
| 1360 |
+
def reset(self, total=None):
|
| 1361 |
+
"""
|
| 1362 |
+
Resets to 0 iterations for repeated use.
|
| 1363 |
+
|
| 1364 |
+
Consider combining with `leave=True`.
|
| 1365 |
+
|
| 1366 |
+
Parameters
|
| 1367 |
+
----------
|
| 1368 |
+
total : int or float, optional. Total to use for the new bar.
|
| 1369 |
+
"""
|
| 1370 |
+
self.n = 0
|
| 1371 |
+
if total is not None:
|
| 1372 |
+
self.total = total
|
| 1373 |
+
if self.disable:
|
| 1374 |
+
return
|
| 1375 |
+
self.last_print_n = 0
|
| 1376 |
+
self.last_print_t = self.start_t = self._time()
|
| 1377 |
+
self._ema_dn = EMA(self.smoothing)
|
| 1378 |
+
self._ema_dt = EMA(self.smoothing)
|
| 1379 |
+
self._ema_miniters = EMA(self.smoothing)
|
| 1380 |
+
self.refresh()
|
| 1381 |
+
|
| 1382 |
+
def set_description(self, desc=None, refresh=True):
|
| 1383 |
+
"""
|
| 1384 |
+
Set/modify description of the progress bar.
|
| 1385 |
+
|
| 1386 |
+
Parameters
|
| 1387 |
+
----------
|
| 1388 |
+
desc : str, optional
|
| 1389 |
+
refresh : bool, optional
|
| 1390 |
+
Forces refresh [default: True].
|
| 1391 |
+
"""
|
| 1392 |
+
self.desc = desc + ': ' if desc else ''
|
| 1393 |
+
if refresh:
|
| 1394 |
+
self.refresh()
|
| 1395 |
+
|
| 1396 |
+
def set_description_str(self, desc=None, refresh=True):
|
| 1397 |
+
"""Set/modify description without ': ' appended."""
|
| 1398 |
+
self.desc = desc or ''
|
| 1399 |
+
if refresh:
|
| 1400 |
+
self.refresh()
|
| 1401 |
+
|
| 1402 |
+
def set_postfix(self, ordered_dict=None, refresh=True, **kwargs):
|
| 1403 |
+
"""
|
| 1404 |
+
Set/modify postfix (additional stats)
|
| 1405 |
+
with automatic formatting based on datatype.
|
| 1406 |
+
|
| 1407 |
+
Parameters
|
| 1408 |
+
----------
|
| 1409 |
+
ordered_dict : dict or OrderedDict, optional
|
| 1410 |
+
refresh : bool, optional
|
| 1411 |
+
Forces refresh [default: True].
|
| 1412 |
+
kwargs : dict, optional
|
| 1413 |
+
"""
|
| 1414 |
+
# Sort in alphabetical order to be more deterministic
|
| 1415 |
+
postfix = OrderedDict([] if ordered_dict is None else ordered_dict)
|
| 1416 |
+
for key in sorted(kwargs.keys()):
|
| 1417 |
+
postfix[key] = kwargs[key]
|
| 1418 |
+
# Preprocess stats according to datatype
|
| 1419 |
+
for key in postfix.keys():
|
| 1420 |
+
# Number: limit the length of the string
|
| 1421 |
+
if isinstance(postfix[key], Number):
|
| 1422 |
+
postfix[key] = self.format_num(postfix[key])
|
| 1423 |
+
# Else for any other type, try to get the string conversion
|
| 1424 |
+
elif not isinstance(postfix[key], str):
|
| 1425 |
+
postfix[key] = str(postfix[key])
|
| 1426 |
+
# Else if it's a string, don't need to preprocess anything
|
| 1427 |
+
# Stitch together to get the final postfix
|
| 1428 |
+
self.postfix = ', '.join(key + '=' + postfix[key].strip()
|
| 1429 |
+
for key in postfix.keys())
|
| 1430 |
+
if refresh:
|
| 1431 |
+
self.refresh()
|
| 1432 |
+
|
| 1433 |
+
def set_postfix_str(self, s='', refresh=True):
|
| 1434 |
+
"""
|
| 1435 |
+
Postfix without dictionary expansion, similar to prefix handling.
|
| 1436 |
+
"""
|
| 1437 |
+
self.postfix = str(s)
|
| 1438 |
+
if refresh:
|
| 1439 |
+
self.refresh()
|
| 1440 |
+
|
| 1441 |
+
def moveto(self, n):
|
| 1442 |
+
# TODO: private method
|
| 1443 |
+
self.fp.write('\n' * n + _term_move_up() * -n)
|
| 1444 |
+
getattr(self.fp, 'flush', lambda: None)()
|
| 1445 |
+
|
| 1446 |
+
@property
|
| 1447 |
+
def format_dict(self):
|
| 1448 |
+
"""Public API for read-only member access."""
|
| 1449 |
+
if self.disable and not hasattr(self, 'unit'):
|
| 1450 |
+
return defaultdict(lambda: None, {
|
| 1451 |
+
'n': self.n, 'total': self.total, 'elapsed': 0, 'unit': 'it'})
|
| 1452 |
+
if self.dynamic_ncols:
|
| 1453 |
+
self.ncols, self.nrows = self.dynamic_ncols(self.fp)
|
| 1454 |
+
return {
|
| 1455 |
+
'n': self.n, 'total': self.total,
|
| 1456 |
+
'elapsed': self._time() - self.start_t if hasattr(self, 'start_t') else 0,
|
| 1457 |
+
'ncols': self.ncols, 'nrows': self.nrows, 'prefix': self.desc,
|
| 1458 |
+
'ascii': self.ascii, 'unit': self.unit, 'unit_scale': self.unit_scale,
|
| 1459 |
+
'rate': self._ema_dn() / self._ema_dt() if self._ema_dt() else None,
|
| 1460 |
+
'bar_format': self.bar_format, 'postfix': self.postfix,
|
| 1461 |
+
'unit_divisor': self.unit_divisor, 'initial': self.initial,
|
| 1462 |
+
'colour': self.colour}
|
| 1463 |
+
|
| 1464 |
+
def display(self, msg=None, pos=None):
|
| 1465 |
+
"""
|
| 1466 |
+
Use `self.sp` to display `msg` in the specified `pos`.
|
| 1467 |
+
|
| 1468 |
+
Consider overloading this function when inheriting to use e.g.:
|
| 1469 |
+
`self.some_frontend(**self.format_dict)` instead of `self.sp`.
|
| 1470 |
+
|
| 1471 |
+
Parameters
|
| 1472 |
+
----------
|
| 1473 |
+
msg : str, optional. What to display (default: `repr(self)`).
|
| 1474 |
+
pos : int, optional. Position to `moveto`
|
| 1475 |
+
(default: `abs(self.pos)`).
|
| 1476 |
+
"""
|
| 1477 |
+
if pos is None:
|
| 1478 |
+
pos = abs(self.pos)
|
| 1479 |
+
|
| 1480 |
+
nrows = self.nrows or 20
|
| 1481 |
+
if pos >= nrows - 1:
|
| 1482 |
+
if pos >= nrows:
|
| 1483 |
+
return False
|
| 1484 |
+
if msg or msg is None: # override at `nrows - 1`
|
| 1485 |
+
msg = " ... (more hidden) ..."
|
| 1486 |
+
|
| 1487 |
+
if not hasattr(self, "sp"):
|
| 1488 |
+
raise TqdmDeprecationWarning(
|
| 1489 |
+
"Please use `tqdm.gui.tqdm(...)`"
|
| 1490 |
+
" instead of `tqdm(..., gui=True)`\n",
|
| 1491 |
+
fp_write=getattr(self.fp, 'write', sys.stderr.write))
|
| 1492 |
+
|
| 1493 |
+
if pos:
|
| 1494 |
+
self.moveto(pos)
|
| 1495 |
+
self.sp(self.__str__() if msg is None else msg)
|
| 1496 |
+
if pos:
|
| 1497 |
+
self.moveto(-pos)
|
| 1498 |
+
return True
|
| 1499 |
+
|
| 1500 |
+
@classmethod
|
| 1501 |
+
@contextmanager
|
| 1502 |
+
def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
|
| 1503 |
+
"""
|
| 1504 |
+
stream : file-like object.
|
| 1505 |
+
method : str, "read" or "write". The result of `read()` and
|
| 1506 |
+
the first argument of `write()` should have a `len()`.
|
| 1507 |
+
|
| 1508 |
+
>>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
|
| 1509 |
+
... while True:
|
| 1510 |
+
... chunk = fobj.read(chunk_size)
|
| 1511 |
+
... if not chunk:
|
| 1512 |
+
... break
|
| 1513 |
+
"""
|
| 1514 |
+
with cls(total=total, **tqdm_kwargs) as t:
|
| 1515 |
+
if bytes:
|
| 1516 |
+
t.unit = "B"
|
| 1517 |
+
t.unit_scale = True
|
| 1518 |
+
t.unit_divisor = 1024
|
| 1519 |
+
yield CallbackIOWrapper(t.update, stream, method)
|
| 1520 |
+
|
| 1521 |
+
|
| 1522 |
+
def trange(*args, **kwargs):
|
| 1523 |
+
"""Shortcut for tqdm(range(*args), **kwargs)."""
|
| 1524 |
+
return tqdm(range(*args), **kwargs)
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/tk.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tkinter GUI progressbar decorator for iterators.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
>>> from tqdm.tk import trange, tqdm
|
| 6 |
+
>>> for i in trange(10):
|
| 7 |
+
... ...
|
| 8 |
+
"""
|
| 9 |
+
import re
|
| 10 |
+
import sys
|
| 11 |
+
import tkinter
|
| 12 |
+
import tkinter.ttk as ttk
|
| 13 |
+
from warnings import warn
|
| 14 |
+
|
| 15 |
+
from .std import TqdmExperimentalWarning, TqdmWarning
|
| 16 |
+
from .std import tqdm as std_tqdm
|
| 17 |
+
|
| 18 |
+
__author__ = {"github.com/": ["richardsheridan", "casperdcl"]}
|
| 19 |
+
__all__ = ['tqdm_tk', 'ttkrange', 'tqdm', 'trange']
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class tqdm_tk(std_tqdm): # pragma: no cover
|
| 23 |
+
"""
|
| 24 |
+
Experimental Tkinter GUI version of tqdm!
|
| 25 |
+
|
| 26 |
+
Note: Window interactivity suffers if `tqdm_tk` is not running within
|
| 27 |
+
a Tkinter mainloop and values are generated infrequently. In this case,
|
| 28 |
+
consider calling `tqdm_tk.refresh()` frequently in the Tk thread.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
# TODO: @classmethod: write()?
|
| 32 |
+
|
| 33 |
+
def __init__(self, *args, **kwargs):
|
| 34 |
+
"""
|
| 35 |
+
This class accepts the following parameters *in addition* to
|
| 36 |
+
the parameters accepted by `tqdm`.
|
| 37 |
+
|
| 38 |
+
Parameters
|
| 39 |
+
----------
|
| 40 |
+
grab : bool, optional
|
| 41 |
+
Grab the input across all windows of the process.
|
| 42 |
+
tk_parent : `tkinter.Wm`, optional
|
| 43 |
+
Parent Tk window.
|
| 44 |
+
cancel_callback : Callable, optional
|
| 45 |
+
Create a cancel button and set `cancel_callback` to be called
|
| 46 |
+
when the cancel or window close button is clicked.
|
| 47 |
+
"""
|
| 48 |
+
kwargs = kwargs.copy()
|
| 49 |
+
kwargs['gui'] = True
|
| 50 |
+
# convert disable = None to False
|
| 51 |
+
kwargs['disable'] = bool(kwargs.get('disable', False))
|
| 52 |
+
self._warn_leave = 'leave' in kwargs
|
| 53 |
+
grab = kwargs.pop('grab', False)
|
| 54 |
+
tk_parent = kwargs.pop('tk_parent', None)
|
| 55 |
+
self._cancel_callback = kwargs.pop('cancel_callback', None)
|
| 56 |
+
super().__init__(*args, **kwargs)
|
| 57 |
+
|
| 58 |
+
if self.disable:
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
if tk_parent is None: # Discover parent widget
|
| 62 |
+
try:
|
| 63 |
+
tk_parent = tkinter._default_root
|
| 64 |
+
except AttributeError:
|
| 65 |
+
raise AttributeError(
|
| 66 |
+
"`tk_parent` required when using `tkinter.NoDefaultRoot()`")
|
| 67 |
+
if tk_parent is None: # use new default root window as display
|
| 68 |
+
self._tk_window = tkinter.Tk()
|
| 69 |
+
else: # some other windows already exist
|
| 70 |
+
self._tk_window = tkinter.Toplevel()
|
| 71 |
+
else:
|
| 72 |
+
self._tk_window = tkinter.Toplevel(tk_parent)
|
| 73 |
+
|
| 74 |
+
warn("GUI is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
|
| 75 |
+
self._tk_dispatching = self._tk_dispatching_helper()
|
| 76 |
+
|
| 77 |
+
self._tk_window.protocol("WM_DELETE_WINDOW", self.cancel)
|
| 78 |
+
self._tk_window.wm_title(self.desc)
|
| 79 |
+
self._tk_window.wm_attributes("-topmost", 1)
|
| 80 |
+
self._tk_window.after(0, lambda: self._tk_window.wm_attributes("-topmost", 0))
|
| 81 |
+
self._tk_n_var = tkinter.DoubleVar(self._tk_window, value=0)
|
| 82 |
+
self._tk_text_var = tkinter.StringVar(self._tk_window)
|
| 83 |
+
pbar_frame = ttk.Frame(self._tk_window, padding=5)
|
| 84 |
+
pbar_frame.pack()
|
| 85 |
+
_tk_label = ttk.Label(pbar_frame, textvariable=self._tk_text_var,
|
| 86 |
+
wraplength=600, anchor="center", justify="center")
|
| 87 |
+
_tk_label.pack()
|
| 88 |
+
self._tk_pbar = ttk.Progressbar(
|
| 89 |
+
pbar_frame, variable=self._tk_n_var, length=450)
|
| 90 |
+
if self.total is not None:
|
| 91 |
+
self._tk_pbar.configure(maximum=self.total)
|
| 92 |
+
else:
|
| 93 |
+
self._tk_pbar.configure(mode="indeterminate")
|
| 94 |
+
self._tk_pbar.pack()
|
| 95 |
+
if self._cancel_callback is not None:
|
| 96 |
+
_tk_button = ttk.Button(pbar_frame, text="Cancel", command=self.cancel)
|
| 97 |
+
_tk_button.pack()
|
| 98 |
+
if grab:
|
| 99 |
+
self._tk_window.grab_set()
|
| 100 |
+
|
| 101 |
+
def close(self):
|
| 102 |
+
if self.disable:
|
| 103 |
+
return
|
| 104 |
+
|
| 105 |
+
self.disable = True
|
| 106 |
+
|
| 107 |
+
with self.get_lock():
|
| 108 |
+
self._instances.remove(self)
|
| 109 |
+
|
| 110 |
+
def _close():
|
| 111 |
+
self._tk_window.after('idle', self._tk_window.destroy)
|
| 112 |
+
if not self._tk_dispatching:
|
| 113 |
+
self._tk_window.update()
|
| 114 |
+
|
| 115 |
+
self._tk_window.protocol("WM_DELETE_WINDOW", _close)
|
| 116 |
+
|
| 117 |
+
# if leave is set but we are self-dispatching, the left window is
|
| 118 |
+
# totally unresponsive unless the user manually dispatches
|
| 119 |
+
if not self.leave:
|
| 120 |
+
_close()
|
| 121 |
+
elif not self._tk_dispatching:
|
| 122 |
+
if self._warn_leave:
|
| 123 |
+
warn("leave flag ignored if not in tkinter mainloop",
|
| 124 |
+
TqdmWarning, stacklevel=2)
|
| 125 |
+
_close()
|
| 126 |
+
|
| 127 |
+
def clear(self, *_, **__):
|
| 128 |
+
pass
|
| 129 |
+
|
| 130 |
+
def display(self, *_, **__):
|
| 131 |
+
self._tk_n_var.set(self.n)
|
| 132 |
+
d = self.format_dict
|
| 133 |
+
# remove {bar}
|
| 134 |
+
d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
|
| 135 |
+
"{bar}", "<bar/>")
|
| 136 |
+
msg = self.format_meter(**d)
|
| 137 |
+
if '<bar/>' in msg:
|
| 138 |
+
msg = "".join(re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
|
| 139 |
+
self._tk_text_var.set(msg)
|
| 140 |
+
if not self._tk_dispatching:
|
| 141 |
+
self._tk_window.update()
|
| 142 |
+
|
| 143 |
+
def set_description(self, desc=None, refresh=True):
|
| 144 |
+
self.set_description_str(desc, refresh)
|
| 145 |
+
|
| 146 |
+
def set_description_str(self, desc=None, refresh=True):
|
| 147 |
+
self.desc = desc
|
| 148 |
+
if not self.disable:
|
| 149 |
+
self._tk_window.wm_title(desc)
|
| 150 |
+
if refresh and not self._tk_dispatching:
|
| 151 |
+
self._tk_window.update()
|
| 152 |
+
|
| 153 |
+
def cancel(self):
|
| 154 |
+
"""
|
| 155 |
+
`cancel_callback()` followed by `close()`
|
| 156 |
+
when close/cancel buttons clicked.
|
| 157 |
+
"""
|
| 158 |
+
if self._cancel_callback is not None:
|
| 159 |
+
self._cancel_callback()
|
| 160 |
+
self.close()
|
| 161 |
+
|
| 162 |
+
def reset(self, total=None):
|
| 163 |
+
"""
|
| 164 |
+
Resets to 0 iterations for repeated use.
|
| 165 |
+
|
| 166 |
+
Parameters
|
| 167 |
+
----------
|
| 168 |
+
total : int or float, optional. Total to use for the new bar.
|
| 169 |
+
"""
|
| 170 |
+
if hasattr(self, '_tk_pbar'):
|
| 171 |
+
if total is None:
|
| 172 |
+
self._tk_pbar.configure(maximum=100, mode="indeterminate")
|
| 173 |
+
else:
|
| 174 |
+
self._tk_pbar.configure(maximum=total, mode="determinate")
|
| 175 |
+
super().reset(total=total)
|
| 176 |
+
|
| 177 |
+
@staticmethod
|
| 178 |
+
def _tk_dispatching_helper():
|
| 179 |
+
"""determine if Tkinter mainloop is dispatching events"""
|
| 180 |
+
codes = {tkinter.mainloop.__code__, tkinter.Misc.mainloop.__code__}
|
| 181 |
+
for frame in sys._current_frames().values():
|
| 182 |
+
while frame:
|
| 183 |
+
if frame.f_code in codes:
|
| 184 |
+
return True
|
| 185 |
+
frame = frame.f_back
|
| 186 |
+
return False
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def ttkrange(*args, **kwargs):
|
| 190 |
+
"""Shortcut for `tqdm.tk.tqdm(range(*args), **kwargs)`."""
|
| 191 |
+
return tqdm_tk(range(*args), **kwargs)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# Aliases
|
| 195 |
+
tqdm = tqdm_tk
|
| 196 |
+
trange = ttkrange
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/tqdm.1
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.\" Automatically generated by Pandoc 3.8.3
|
| 2 |
+
.\"
|
| 3 |
+
.TH "TQDM" "1" "2015\-2026" "tqdm User Manuals"
|
| 4 |
+
.SH NAME
|
| 5 |
+
tqdm \- fast, extensible progress bar for Python and CLI
|
| 6 |
+
.SH SYNOPSIS
|
| 7 |
+
tqdm [\f[I]options\f[R]]
|
| 8 |
+
.SH DESCRIPTION
|
| 9 |
+
See \c
|
| 10 |
+
.UR https://github.com/tqdm/tqdm
|
| 11 |
+
.UE \c
|
| 12 |
+
\&.
|
| 13 |
+
Can be used as a pipe:
|
| 14 |
+
.IP
|
| 15 |
+
.EX
|
| 16 |
+
$ \f[I]# count lines of code\f[R]
|
| 17 |
+
$ cat *.py \f[B]|\f[R] tqdm \f[B]|\f[R] wc \-l
|
| 18 |
+
327it [00:00, 981773.38it/s]
|
| 19 |
+
327
|
| 20 |
+
|
| 21 |
+
$ \f[I]# find all files\f[R]
|
| 22 |
+
$ find . \-name \(dq*.py\(dq \f[B]|\f[R] tqdm \f[B]|\f[R] wc \-l
|
| 23 |
+
432it [00:00, 833842.30it/s]
|
| 24 |
+
432
|
| 25 |
+
|
| 26 |
+
\f[I]# ... and more info\f[R]
|
| 27 |
+
$ find . \-name \(aq*.py\(aq \-exec wc \-l \(rs{} \(rs; \(rs
|
| 28 |
+
\f[B]|\f[R] tqdm \-\-total 432 \-\-unit files \-\-desc counting \(rs
|
| 29 |
+
\f[B]|\f[R] awk \(aq{ sum += $1 }; END { print sum }\(aq
|
| 30 |
+
counting: 100%\f[B]|\f[R]█████████\f[B]|\f[R] 432/432 [00:00<00:00, 794361.83files/s]
|
| 31 |
+
131998
|
| 32 |
+
.EE
|
| 33 |
+
.SH OPTIONS
|
| 34 |
+
.TP
|
| 35 |
+
\-h, \-\-help
|
| 36 |
+
Print this help and exit.
|
| 37 |
+
.TP
|
| 38 |
+
\-v, \-\-version
|
| 39 |
+
Print version and exit.
|
| 40 |
+
.TP
|
| 41 |
+
\-\-desc=\f[I]desc\f[R]
|
| 42 |
+
str, optional.
|
| 43 |
+
Prefix for the progressbar.
|
| 44 |
+
.TP
|
| 45 |
+
\-\-total=\f[I]total\f[R]
|
| 46 |
+
int or float, optional.
|
| 47 |
+
The number of expected iterations.
|
| 48 |
+
If unspecified, len(iterable) is used if possible.
|
| 49 |
+
If float(\(lqinf\(rq) or as a last resort, only basic progress
|
| 50 |
+
statistics are displayed (no ETA, no progressbar).
|
| 51 |
+
If \f[CR]gui\f[R] is True and this parameter needs subsequent updating,
|
| 52 |
+
specify an initial arbitrary large positive number, e.g.\ 9e9.
|
| 53 |
+
.TP
|
| 54 |
+
\-\-leave
|
| 55 |
+
bool, optional.
|
| 56 |
+
If [default: True], keeps all traces of the progressbar upon termination
|
| 57 |
+
of iteration.
|
| 58 |
+
If \f[CR]None\f[R], will leave only if \f[CR]position\f[R] is
|
| 59 |
+
\f[CR]0\f[R].
|
| 60 |
+
.TP
|
| 61 |
+
\-\-ncols=\f[I]ncols\f[R]
|
| 62 |
+
int, optional.
|
| 63 |
+
The width of the entire output message.
|
| 64 |
+
If specified, dynamically resizes the progressbar to stay within this
|
| 65 |
+
bound.
|
| 66 |
+
If unspecified, attempts to use environment width.
|
| 67 |
+
The fallback is a meter width of 10 and no limit for the counter and
|
| 68 |
+
statistics.
|
| 69 |
+
If 0, will not print any meter (only stats).
|
| 70 |
+
.TP
|
| 71 |
+
\-\-mininterval=\f[I]mininterval\f[R]
|
| 72 |
+
float, optional.
|
| 73 |
+
Minimum progress display update interval [default: 0.1] seconds.
|
| 74 |
+
.TP
|
| 75 |
+
\-\-maxinterval=\f[I]maxinterval\f[R]
|
| 76 |
+
float, optional.
|
| 77 |
+
Maximum progress display update interval [default: 10] seconds.
|
| 78 |
+
Automatically adjusts \f[CR]miniters\f[R] to correspond to
|
| 79 |
+
\f[CR]mininterval\f[R] after long display update lag.
|
| 80 |
+
Only works if \f[CR]dynamic_miniters\f[R] or monitor thread is enabled.
|
| 81 |
+
.TP
|
| 82 |
+
\-\-miniters=\f[I]miniters\f[R]
|
| 83 |
+
int or float, optional.
|
| 84 |
+
Minimum progress display update interval, in iterations.
|
| 85 |
+
If 0 and \f[CR]dynamic_miniters\f[R], will automatically adjust to equal
|
| 86 |
+
\f[CR]mininterval\f[R] (more CPU efficient, good for tight loops).
|
| 87 |
+
If > 0, will skip display of specified number of iterations.
|
| 88 |
+
Tweak this and \f[CR]mininterval\f[R] to get very efficient loops.
|
| 89 |
+
If your progress is erratic with both fast and slow iterations (network,
|
| 90 |
+
skipping items, etc) you should set miniters=1.
|
| 91 |
+
.TP
|
| 92 |
+
\-\-ascii=\f[I]ascii\f[R]
|
| 93 |
+
bool or str, optional.
|
| 94 |
+
If unspecified or False, use unicode (smooth blocks) to fill the meter.
|
| 95 |
+
The fallback is to use ASCII characters \(rq 123456789#\(lq.
|
| 96 |
+
.TP
|
| 97 |
+
\-\-disable
|
| 98 |
+
bool, optional.
|
| 99 |
+
Whether to disable the entire progressbar wrapper [default: False].
|
| 100 |
+
If set to None, disable on non\-TTY.
|
| 101 |
+
.TP
|
| 102 |
+
\-\-unit=\f[I]unit\f[R]
|
| 103 |
+
str, optional.
|
| 104 |
+
String that will be used to define the unit of each iteration [default:
|
| 105 |
+
it].
|
| 106 |
+
.TP
|
| 107 |
+
\-\-unit\-scale=\f[I]unit_scale\f[R]
|
| 108 |
+
bool or int or float, optional.
|
| 109 |
+
If 1 or True, the number of iterations will be reduced/scaled
|
| 110 |
+
automatically and a metric prefix following the International System of
|
| 111 |
+
Units standard will be added (kilo, mega, etc.)
|
| 112 |
+
[default: False].
|
| 113 |
+
If any other non\-zero number, will scale \f[CR]total\f[R] and
|
| 114 |
+
\f[CR]n\f[R].
|
| 115 |
+
.TP
|
| 116 |
+
\-\-dynamic\-ncols
|
| 117 |
+
bool, optional.
|
| 118 |
+
If set, constantly alters \f[CR]ncols\f[R] and \f[CR]nrows\f[R] to the
|
| 119 |
+
environment (allowing for window resizes) [default: False].
|
| 120 |
+
.TP
|
| 121 |
+
\-\-smoothing=\f[I]smoothing\f[R]
|
| 122 |
+
float, optional.
|
| 123 |
+
Exponential moving average smoothing factor for speed estimates (ignored
|
| 124 |
+
in GUI mode).
|
| 125 |
+
Ranges from 0 (average speed) to 1 (current/instantaneous speed)
|
| 126 |
+
[default: 0.3].
|
| 127 |
+
.TP
|
| 128 |
+
\-\-bar\-format=\f[I]bar_format\f[R]
|
| 129 |
+
str, optional.
|
| 130 |
+
Specify a custom bar string formatting.
|
| 131 |
+
May impact performance.
|
| 132 |
+
[default: `{l_bar}{bar}{r_bar}'], where l_bar=`{desc}:
|
| 133 |
+
{percentage:3.0f}%|' and r_bar=`| {n_fmt}/{total_fmt}
|
| 134 |
+
[{elapsed}<{remaining}, \(cq \(cq{rate_fmt}{postfix}]' Possible vars:
|
| 135 |
+
l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage, elapsed,
|
| 136 |
+
elapsed_s, ncols, nrows, desc, unit, rate, rate_fmt, rate_noinv,
|
| 137 |
+
rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
| 138 |
+
remaining, remaining_s, eta.
|
| 139 |
+
Note that a trailing \(lq:\(rq is automatically removed after {desc} if
|
| 140 |
+
the latter is empty.
|
| 141 |
+
.TP
|
| 142 |
+
\-\-initial=\f[I]initial\f[R]
|
| 143 |
+
int or float, optional.
|
| 144 |
+
The initial counter value.
|
| 145 |
+
Useful when restarting a progress bar [default: 0].
|
| 146 |
+
If using float, consider specifying \f[CR]{n:.3f}\f[R] or similar in
|
| 147 |
+
\f[CR]bar_format\f[R], or specifying \f[CR]unit_scale\f[R].
|
| 148 |
+
.TP
|
| 149 |
+
\-\-position=\f[I]position\f[R]
|
| 150 |
+
int, optional.
|
| 151 |
+
Specify the line offset to print this bar (starting from 0) Automatic if
|
| 152 |
+
unspecified.
|
| 153 |
+
Useful to manage multiple bars at once (eg, from threads).
|
| 154 |
+
.TP
|
| 155 |
+
\-\-postfix=\f[I]postfix\f[R]
|
| 156 |
+
dict or *, optional.
|
| 157 |
+
Specify additional stats to display at the end of the bar.
|
| 158 |
+
Calls \f[CR]set_postfix(**postfix)\f[R] if possible (dict).
|
| 159 |
+
.TP
|
| 160 |
+
\-\-unit\-divisor=\f[I]unit_divisor\f[R]
|
| 161 |
+
float, optional.
|
| 162 |
+
[default: 1000], ignored unless \f[CR]unit_scale\f[R] is True.
|
| 163 |
+
.TP
|
| 164 |
+
\-\-write\-bytes
|
| 165 |
+
bool, optional.
|
| 166 |
+
Whether to write bytes.
|
| 167 |
+
If (default: False) will write unicode.
|
| 168 |
+
.TP
|
| 169 |
+
\-\-lock\-args=\f[I]lock_args\f[R]
|
| 170 |
+
tuple, optional.
|
| 171 |
+
Passed to \f[CR]refresh\f[R] for intermediate output (initialisation,
|
| 172 |
+
iterating, and updating).
|
| 173 |
+
.TP
|
| 174 |
+
\-\-nrows=\f[I]nrows\f[R]
|
| 175 |
+
int, optional.
|
| 176 |
+
The screen height.
|
| 177 |
+
If specified, hides nested bars outside this bound.
|
| 178 |
+
If unspecified, attempts to use environment height.
|
| 179 |
+
The fallback is 20.
|
| 180 |
+
.TP
|
| 181 |
+
\-\-colour=\f[I]colour\f[R]
|
| 182 |
+
str, optional.
|
| 183 |
+
Bar colour (e.g.\ `green', `#00ff00').
|
| 184 |
+
.TP
|
| 185 |
+
\-\-delay=\f[I]delay\f[R]
|
| 186 |
+
float, optional.
|
| 187 |
+
Don\(cqt display until [default: 0] seconds have elapsed.
|
| 188 |
+
.TP
|
| 189 |
+
\-\-delim=\f[I]delim\f[R]
|
| 190 |
+
chr, optional.
|
| 191 |
+
Delimiting character [default: `\(rsn'].
|
| 192 |
+
Use `\(rs0' for null.
|
| 193 |
+
N.B.: on Windows systems, Python converts `\(rsn' to `\(rsr\(rsn'.
|
| 194 |
+
.TP
|
| 195 |
+
\-\-buf\-size=\f[I]buf_size\f[R]
|
| 196 |
+
int, optional.
|
| 197 |
+
String buffer size in bytes [default: 256] used when \f[CR]delim\f[R] is
|
| 198 |
+
specified.
|
| 199 |
+
.TP
|
| 200 |
+
\-\-bytes
|
| 201 |
+
bool, optional.
|
| 202 |
+
If true, will count bytes, ignore \f[CR]delim\f[R], and default
|
| 203 |
+
\f[CR]unit_scale\f[R] to True, \f[CR]unit_divisor\f[R] to 1024, and
|
| 204 |
+
\f[CR]unit\f[R] to `B'.
|
| 205 |
+
.TP
|
| 206 |
+
\-\-tee
|
| 207 |
+
bool, optional.
|
| 208 |
+
If true, passes \f[CR]stdin\f[R] to both \f[CR]stderr\f[R] and
|
| 209 |
+
\f[CR]stdout\f[R].
|
| 210 |
+
.TP
|
| 211 |
+
\-\-update
|
| 212 |
+
bool, optional.
|
| 213 |
+
If true, will treat input as newly elapsed iterations, i.e.\ numbers to
|
| 214 |
+
pass to \f[CR]update()\f[R].
|
| 215 |
+
Note that this is slow (\(ti2e5 it/s) since every input must be decoded
|
| 216 |
+
as a number.
|
| 217 |
+
.TP
|
| 218 |
+
\-\-update\-to
|
| 219 |
+
bool, optional.
|
| 220 |
+
If true, will treat input as total elapsed iterations, i.e.\ numbers to
|
| 221 |
+
assign to \f[CR]self.n\f[R].
|
| 222 |
+
Note that this is slow (\(ti2e5 it/s) since every input must be decoded
|
| 223 |
+
as a number.
|
| 224 |
+
.TP
|
| 225 |
+
\-\-null
|
| 226 |
+
bool, optional.
|
| 227 |
+
If true, will discard input (no stdout).
|
| 228 |
+
.TP
|
| 229 |
+
\-\-manpath=\f[I]manpath\f[R]
|
| 230 |
+
str, optional.
|
| 231 |
+
Directory in which to install tqdm man pages.
|
| 232 |
+
.TP
|
| 233 |
+
\-\-comppath=\f[I]comppath\f[R]
|
| 234 |
+
str, optional.
|
| 235 |
+
Directory in which to place tqdm completion.
|
| 236 |
+
.TP
|
| 237 |
+
\-\-log=\f[I]log\f[R]
|
| 238 |
+
str, optional.
|
| 239 |
+
CRITICAL|FATAL|ERROR|WARN(ING)|[default: `INFO']|DEBUG|NOTSET.
|
| 240 |
+
.SH AUTHORS
|
| 241 |
+
tqdm developers \c
|
| 242 |
+
.UR https://github.com/tqdm
|
| 243 |
+
.UE \c.
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/utils.py
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
General helpers required for `tqdm.std`.
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
from functools import partial, partialmethod, wraps
|
| 8 |
+
from inspect import signature
|
| 9 |
+
# TODO consider using wcswidth third-party package for 0-width characters
|
| 10 |
+
from unicodedata import east_asian_width
|
| 11 |
+
from warnings import warn
|
| 12 |
+
from weakref import proxy
|
| 13 |
+
|
| 14 |
+
_range, _unich, _unicode, _basestring = range, chr, str, str
|
| 15 |
+
CUR_OS = sys.platform
|
| 16 |
+
IS_WIN = any(CUR_OS.startswith(i) for i in ['win32', 'cygwin'])
|
| 17 |
+
IS_NIX = any(CUR_OS.startswith(i) for i in ['aix', 'linux', 'darwin', 'freebsd'])
|
| 18 |
+
RE_ANSI = re.compile(r"\x1b\[[;\d]*[A-Za-z]")
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
if IS_WIN:
|
| 22 |
+
import colorama
|
| 23 |
+
else:
|
| 24 |
+
raise ImportError
|
| 25 |
+
except ImportError:
|
| 26 |
+
colorama = None
|
| 27 |
+
else:
|
| 28 |
+
try:
|
| 29 |
+
colorama.init(strip=False)
|
| 30 |
+
except TypeError:
|
| 31 |
+
colorama.init()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def envwrap(prefix, types=None, is_method=False):
|
| 35 |
+
"""
|
| 36 |
+
Override parameter defaults via `os.environ[prefix + param_name]`.
|
| 37 |
+
Maps UPPER_CASE env vars map to lower_case param names.
|
| 38 |
+
camelCase isn't supported (because Windows ignores case).
|
| 39 |
+
|
| 40 |
+
Precedence (highest first):
|
| 41 |
+
|
| 42 |
+
- call (`foo(a=3)`)
|
| 43 |
+
- environ (`FOO_A=2`)
|
| 44 |
+
- signature (`def foo(a=1)`)
|
| 45 |
+
|
| 46 |
+
Parameters
|
| 47 |
+
----------
|
| 48 |
+
prefix : str
|
| 49 |
+
Env var prefix, e.g. "FOO_"
|
| 50 |
+
types : dict, optional
|
| 51 |
+
Fallback mappings `{'param_name': type, ...}` if types cannot be
|
| 52 |
+
inferred from function signature.
|
| 53 |
+
Consider using `types=collections.defaultdict(lambda: ast.literal_eval)`.
|
| 54 |
+
is_method : bool, optional
|
| 55 |
+
Whether to use `functools.partialmethod`. If (default: False) use `functools.partial`.
|
| 56 |
+
|
| 57 |
+
Examples
|
| 58 |
+
--------
|
| 59 |
+
```
|
| 60 |
+
$ cat foo.py
|
| 61 |
+
from tqdm.utils import envwrap
|
| 62 |
+
@envwrap("FOO_")
|
| 63 |
+
def test(a=1, b=2, c=3):
|
| 64 |
+
print(f"received: a={a}, b={b}, c={c}")
|
| 65 |
+
|
| 66 |
+
$ FOO_A=42 FOO_C=1337 python -c 'import foo; foo.test(c=99)'
|
| 67 |
+
received: a=42, b=2, c=99
|
| 68 |
+
```
|
| 69 |
+
"""
|
| 70 |
+
if types is None:
|
| 71 |
+
types = {}
|
| 72 |
+
i = len(prefix)
|
| 73 |
+
env_overrides = {k[i:].lower(): v for k, v in os.environ.items() if k.startswith(prefix)}
|
| 74 |
+
part = partialmethod if is_method else partial
|
| 75 |
+
|
| 76 |
+
def wrap(func):
|
| 77 |
+
params = signature(func).parameters
|
| 78 |
+
# ignore unknown env vars
|
| 79 |
+
overrides = {k: v for k, v in env_overrides.items() if k in params}
|
| 80 |
+
# infer overrides' `type`s
|
| 81 |
+
for k in overrides:
|
| 82 |
+
param = params[k]
|
| 83 |
+
if param.annotation is not param.empty: # typehints
|
| 84 |
+
for typ in getattr(param.annotation, '__args__', (param.annotation,)):
|
| 85 |
+
try:
|
| 86 |
+
overrides[k] = typ(overrides[k])
|
| 87 |
+
except Exception:
|
| 88 |
+
pass
|
| 89 |
+
else:
|
| 90 |
+
break
|
| 91 |
+
elif param.default is not None: # type of default value
|
| 92 |
+
overrides[k] = type(param.default)(overrides[k])
|
| 93 |
+
else:
|
| 94 |
+
try: # `types` fallback
|
| 95 |
+
overrides[k] = types[k](overrides[k])
|
| 96 |
+
except KeyError: # keep unconverted (`str`)
|
| 97 |
+
pass
|
| 98 |
+
return part(func, **overrides)
|
| 99 |
+
return wrap
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class FormatReplace:
|
| 103 |
+
"""
|
| 104 |
+
>>> a = FormatReplace('something')
|
| 105 |
+
>>> f"{a:5d}"
|
| 106 |
+
'something'
|
| 107 |
+
""" # NOQA: P102
|
| 108 |
+
def __init__(self, replace=''):
|
| 109 |
+
self.replace = replace
|
| 110 |
+
self.format_called = 0
|
| 111 |
+
|
| 112 |
+
def __format__(self, _):
|
| 113 |
+
self.format_called += 1
|
| 114 |
+
return self.replace
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class Comparable:
|
| 118 |
+
"""Assumes child has self._comparable attr/@property"""
|
| 119 |
+
def __lt__(self, other):
|
| 120 |
+
return self._comparable < other._comparable
|
| 121 |
+
|
| 122 |
+
def __le__(self, other):
|
| 123 |
+
return (self < other) or (self == other)
|
| 124 |
+
|
| 125 |
+
def __eq__(self, other):
|
| 126 |
+
return self._comparable == other._comparable
|
| 127 |
+
|
| 128 |
+
def __ne__(self, other):
|
| 129 |
+
return not self == other
|
| 130 |
+
|
| 131 |
+
def __gt__(self, other):
|
| 132 |
+
return not self <= other
|
| 133 |
+
|
| 134 |
+
def __ge__(self, other):
|
| 135 |
+
return not self < other
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class ObjectWrapper:
|
| 139 |
+
def __getattr__(self, name):
|
| 140 |
+
return getattr(self._wrapped, name)
|
| 141 |
+
|
| 142 |
+
def __setattr__(self, name, value):
|
| 143 |
+
return setattr(self._wrapped, name, value)
|
| 144 |
+
|
| 145 |
+
def wrapper_getattr(self, name):
|
| 146 |
+
"""Actual `self.getattr` rather than self._wrapped.getattr"""
|
| 147 |
+
try:
|
| 148 |
+
return object.__getattr__(self, name)
|
| 149 |
+
except AttributeError: # py2
|
| 150 |
+
return getattr(self, name)
|
| 151 |
+
|
| 152 |
+
def wrapper_setattr(self, name, value):
|
| 153 |
+
"""Actual `self.setattr` rather than self._wrapped.setattr"""
|
| 154 |
+
return object.__setattr__(self, name, value)
|
| 155 |
+
|
| 156 |
+
def __init__(self, wrapped):
|
| 157 |
+
"""
|
| 158 |
+
Thin wrapper around a given object
|
| 159 |
+
"""
|
| 160 |
+
self.wrapper_setattr('_wrapped', wrapped)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class SimpleTextIOWrapper(ObjectWrapper):
|
| 164 |
+
"""
|
| 165 |
+
Change only `.write()` of the wrapped object by encoding the passed
|
| 166 |
+
value and passing the result to the wrapped object's `.write()` method.
|
| 167 |
+
"""
|
| 168 |
+
# pylint: disable=too-few-public-methods
|
| 169 |
+
def __init__(self, wrapped, encoding):
|
| 170 |
+
super().__init__(wrapped)
|
| 171 |
+
self.wrapper_setattr('encoding', encoding)
|
| 172 |
+
|
| 173 |
+
def write(self, s):
|
| 174 |
+
"""
|
| 175 |
+
Encode `s` and pass to the wrapped object's `.write()` method.
|
| 176 |
+
"""
|
| 177 |
+
return self._wrapped.write(s.encode(self.wrapper_getattr('encoding')))
|
| 178 |
+
|
| 179 |
+
def __eq__(self, other):
|
| 180 |
+
return self._wrapped == getattr(other, '_wrapped', other)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class DisableOnWriteError(ObjectWrapper):
|
| 184 |
+
"""
|
| 185 |
+
Disable the given `tqdm_instance` upon `write()` or `flush()` errors.
|
| 186 |
+
"""
|
| 187 |
+
@staticmethod
|
| 188 |
+
def disable_on_exception(tqdm_instance, func):
|
| 189 |
+
"""
|
| 190 |
+
Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`.
|
| 191 |
+
"""
|
| 192 |
+
tqdm_instance = proxy(tqdm_instance)
|
| 193 |
+
|
| 194 |
+
def inner(*args, **kwargs):
|
| 195 |
+
try:
|
| 196 |
+
return func(*args, **kwargs)
|
| 197 |
+
except OSError as e:
|
| 198 |
+
if e.errno != 5:
|
| 199 |
+
raise
|
| 200 |
+
try:
|
| 201 |
+
tqdm_instance.miniters = float('inf')
|
| 202 |
+
except ReferenceError:
|
| 203 |
+
pass
|
| 204 |
+
except ValueError as e:
|
| 205 |
+
if 'closed' not in str(e):
|
| 206 |
+
raise
|
| 207 |
+
try:
|
| 208 |
+
tqdm_instance.miniters = float('inf')
|
| 209 |
+
except ReferenceError:
|
| 210 |
+
pass
|
| 211 |
+
return inner
|
| 212 |
+
|
| 213 |
+
def __init__(self, wrapped, tqdm_instance): # noqa: B042
|
| 214 |
+
super().__init__(wrapped)
|
| 215 |
+
if hasattr(wrapped, 'write'):
|
| 216 |
+
self.wrapper_setattr(
|
| 217 |
+
'write', self.disable_on_exception(tqdm_instance, wrapped.write))
|
| 218 |
+
if hasattr(wrapped, 'flush'):
|
| 219 |
+
self.wrapper_setattr(
|
| 220 |
+
'flush', self.disable_on_exception(tqdm_instance, wrapped.flush))
|
| 221 |
+
|
| 222 |
+
def __eq__(self, other):
|
| 223 |
+
return self._wrapped == getattr(other, '_wrapped', other)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
class CallbackIOWrapper(ObjectWrapper):
|
| 227 |
+
def __init__(self, callback, stream, method="read"):
|
| 228 |
+
"""
|
| 229 |
+
Wrap a given `file`-like object's `read()` or `write()` to report
|
| 230 |
+
lengths to the given `callback`
|
| 231 |
+
"""
|
| 232 |
+
super().__init__(stream)
|
| 233 |
+
func = getattr(stream, method)
|
| 234 |
+
if method == "write":
|
| 235 |
+
@wraps(func)
|
| 236 |
+
def write(data, *args, **kwargs):
|
| 237 |
+
res = func(data, *args, **kwargs)
|
| 238 |
+
callback(len(data))
|
| 239 |
+
return res
|
| 240 |
+
self.wrapper_setattr('write', write)
|
| 241 |
+
elif method == "read":
|
| 242 |
+
@wraps(func)
|
| 243 |
+
def read(*args, **kwargs):
|
| 244 |
+
data = func(*args, **kwargs)
|
| 245 |
+
callback(len(data))
|
| 246 |
+
return data
|
| 247 |
+
self.wrapper_setattr('read', read)
|
| 248 |
+
else:
|
| 249 |
+
raise KeyError("Can only wrap read/write methods")
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def _is_utf(encoding):
|
| 253 |
+
try:
|
| 254 |
+
'\u2588\u2589'.encode(encoding)
|
| 255 |
+
except UnicodeEncodeError:
|
| 256 |
+
return False
|
| 257 |
+
except Exception:
|
| 258 |
+
try:
|
| 259 |
+
return encoding.lower().startswith('utf-') or ('U8' == encoding)
|
| 260 |
+
except Exception:
|
| 261 |
+
return False
|
| 262 |
+
else:
|
| 263 |
+
return True
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _supports_unicode(fp):
|
| 267 |
+
try:
|
| 268 |
+
return _is_utf(fp.encoding)
|
| 269 |
+
except AttributeError:
|
| 270 |
+
return False
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def _is_ascii(s):
|
| 274 |
+
if isinstance(s, str):
|
| 275 |
+
for c in s:
|
| 276 |
+
if ord(c) > 255:
|
| 277 |
+
return False
|
| 278 |
+
return True
|
| 279 |
+
return _supports_unicode(s)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def _screen_shape_wrapper(): # pragma: no cover
|
| 283 |
+
"""
|
| 284 |
+
Return a function which returns console dimensions (width, height).
|
| 285 |
+
Supported: linux, osx, windows, cygwin.
|
| 286 |
+
"""
|
| 287 |
+
_screen_shape = None
|
| 288 |
+
if IS_WIN:
|
| 289 |
+
_screen_shape = _screen_shape_windows
|
| 290 |
+
if _screen_shape is None:
|
| 291 |
+
_screen_shape = _screen_shape_tput
|
| 292 |
+
if IS_NIX:
|
| 293 |
+
_screen_shape = _screen_shape_linux
|
| 294 |
+
return _screen_shape
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def _screen_shape_windows(fp): # pragma: no cover
|
| 298 |
+
try:
|
| 299 |
+
import struct
|
| 300 |
+
from ctypes import create_string_buffer, windll
|
| 301 |
+
from sys import stdin, stdout
|
| 302 |
+
|
| 303 |
+
io_handle = -12 # assume stderr
|
| 304 |
+
if fp == stdin:
|
| 305 |
+
io_handle = -10
|
| 306 |
+
elif fp == stdout:
|
| 307 |
+
io_handle = -11
|
| 308 |
+
|
| 309 |
+
h = windll.kernel32.GetStdHandle(io_handle)
|
| 310 |
+
csbi = create_string_buffer(22)
|
| 311 |
+
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
|
| 312 |
+
if res:
|
| 313 |
+
(_bufx, _bufy, _curx, _cury, _wattr, left, top, right, bottom,
|
| 314 |
+
_maxx, _maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
|
| 315 |
+
return right - left, bottom - top # +1
|
| 316 |
+
except Exception: # nosec
|
| 317 |
+
pass
|
| 318 |
+
return None, None
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def _screen_shape_tput(*_): # pragma: no cover
|
| 322 |
+
"""cygwin xterm (windows)"""
|
| 323 |
+
try:
|
| 324 |
+
import shlex
|
| 325 |
+
from subprocess import check_call # nosec
|
| 326 |
+
return [int(check_call(shlex.split('tput ' + i))) - 1
|
| 327 |
+
for i in ('cols', 'lines')]
|
| 328 |
+
except Exception: # nosec
|
| 329 |
+
pass
|
| 330 |
+
return None, None
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def _screen_shape_linux(fp): # pragma: no cover
|
| 334 |
+
|
| 335 |
+
try:
|
| 336 |
+
from array import array
|
| 337 |
+
from fcntl import ioctl
|
| 338 |
+
from termios import TIOCGWINSZ
|
| 339 |
+
except ImportError:
|
| 340 |
+
return None, None
|
| 341 |
+
else:
|
| 342 |
+
try:
|
| 343 |
+
rows, cols = array('h', ioctl(fp, TIOCGWINSZ, '\0' * 8))[:2]
|
| 344 |
+
return cols, rows
|
| 345 |
+
except Exception:
|
| 346 |
+
try:
|
| 347 |
+
return [int(os.environ[i]) - 1 for i in ("COLUMNS", "LINES")]
|
| 348 |
+
except (KeyError, ValueError):
|
| 349 |
+
return None, None
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def _environ_cols_wrapper(): # pragma: no cover
|
| 353 |
+
"""
|
| 354 |
+
Return a function which returns console width.
|
| 355 |
+
Supported: linux, osx, windows, cygwin.
|
| 356 |
+
"""
|
| 357 |
+
warn("Use `_screen_shape_wrapper()(file)[0]` instead of"
|
| 358 |
+
" `_environ_cols_wrapper()(file)`", DeprecationWarning, stacklevel=2)
|
| 359 |
+
shape = _screen_shape_wrapper()
|
| 360 |
+
if not shape:
|
| 361 |
+
return None
|
| 362 |
+
|
| 363 |
+
@wraps(shape)
|
| 364 |
+
def inner(fp):
|
| 365 |
+
return shape(fp)[0]
|
| 366 |
+
|
| 367 |
+
return inner
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def _term_move_up(): # pragma: no cover
|
| 371 |
+
return '' if (os.name == 'nt') and (colorama is None) else '\x1b[A'
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def _text_width(s):
|
| 375 |
+
return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in str(s))
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def disp_len(data):
|
| 379 |
+
"""
|
| 380 |
+
Returns the real on-screen length of a string which may contain
|
| 381 |
+
ANSI control codes and wide chars.
|
| 382 |
+
"""
|
| 383 |
+
return _text_width(RE_ANSI.sub('', data))
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def disp_trim(data, length):
|
| 387 |
+
"""
|
| 388 |
+
Trim a string which may contain ANSI control characters.
|
| 389 |
+
"""
|
| 390 |
+
if len(data) == disp_len(data):
|
| 391 |
+
return data[:length]
|
| 392 |
+
|
| 393 |
+
ansi_present = bool(RE_ANSI.search(data))
|
| 394 |
+
while disp_len(data) > length: # carefully delete one char at a time
|
| 395 |
+
data = data[:-1]
|
| 396 |
+
if ansi_present and bool(RE_ANSI.search(data)):
|
| 397 |
+
# assume ANSI reset is required
|
| 398 |
+
return data if data.endswith("\033[0m") else data + "\033[0m"
|
| 399 |
+
return data
|
loan-advisor-agent/.venv/Lib/site-packages/tqdm/version.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""`tqdm` version detector. Precedence: installed dist, git, 'UNKNOWN'."""
|
| 2 |
+
try:
|
| 3 |
+
from importlib.metadata import PackageNotFoundError, version
|
| 4 |
+
except ImportError: # py<3.8
|
| 5 |
+
from importlib_metadata import PackageNotFoundError, version
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
__version__ = version('tqdm')
|
| 9 |
+
except PackageNotFoundError:
|
| 10 |
+
__version__ = "UNKNOWN"
|