Provides `update_to(n)` which uses `tqdm.update(delta_n)`. Inspired by the example in https://github.com/tqdm/tqdm.
| 95 | if has_tqdm and progress: |
| 96 | |
| 97 | class TqdmUpTo(tqdm): |
| 98 | """ |
| 99 | Provides `update_to(n)` which uses `tqdm.update(delta_n)`. |
| 100 | Inspired by the example in https://github.com/tqdm/tqdm. |
| 101 | """ |
| 102 | |
| 103 | def update_to(self, b: int = 1, bsize: int = 1, tsize: int | None = None) -> None: |
| 104 | """ |
| 105 | Args: |
| 106 | b: number of blocks transferred so far, default: 1. |
| 107 | bsize: size of each block (in tqdm units), default: 1. |
| 108 | tsize: total size (in tqdm units). if None, remains unchanged. |
| 109 | """ |
| 110 | if tsize is not None: |
| 111 | self.total = tsize |
| 112 | self.update(b * bsize - self.n) # will also set self.n = b * bsize |
| 113 | |
| 114 | with TqdmUpTo(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=_basename(filepath)) as t: |
| 115 | urlretrieve(url, filepath, reporthook=t.update_to) |
no outgoing calls
no test coverage detected
searching dependent graphs…