Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
progress_bars.py
Go to the documentation of this file.
1import functools
2from typing import Callable, Generator, Iterable, Iterator, Optional, Tuple
3
5 BarColumn,
6 DownloadColumn,
7 FileSizeColumn,
8 Progress,
9 ProgressColumn,
10 SpinnerColumn,
11 TextColumn,
12 TimeElapsedColumn,
13 TimeRemainingColumn,
14 TransferSpeedColumn,
15)
16
17from pip._internal.utils.logging import get_indentation
18
19DownloadProgressRenderer = Callable[[Iterable[bytes]], Iterator[bytes]]
20
21
23 iterable: Iterable[bytes],
24 *,
25 bar_type: str,
26 size: int,
27) -> Generator[bytes, None, None]:
28 assert bar_type == "on", "This should only be used in the default mode."
29
30 if not size:
31 total = float("inf")
32 columns: Tuple[ProgressColumn, ...] = (
33 TextColumn("[progress.description]{task.description}"),
34 SpinnerColumn("line", speed=1.5),
38 )
39 else:
40 total = size
41 columns = (
42 TextColumn("[progress.description]{task.description}"),
43 BarColumn(),
46 TextColumn("eta"),
48 )
49
50 progress = Progress(*columns, refresh_per_second=30)
51 task_id = progress.add_task(" " * (get_indentation() + 2), total=total)
52 with progress:
53 for chunk in iterable:
54 yield chunk
55 progress.update(task_id, advance=len(chunk))
56
57
58def get_download_progress_renderer(
59 *, bar_type: str, size: Optional[int] = None
60) -> DownloadProgressRenderer:
61 """Get an object that can be used to render the download progress.
62
63 Returns a callable, that takes an iterable to "wrap".
64 """
65 if bar_type == "on":
66 return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size)
67 else:
68 return iter # no-op, when passed an iterator
Generator[bytes, None, None] _rich_progress_bar(Iterable[bytes] iterable, *str bar_type, int size)
for i