Method: rich.progress.DownloadColumn.render
Calls: 8, Exceptions: 0, Paths: 2Back
Path 1: 7 calls (0.88)
Task (7)
Text (7)
1def render(self, task: "Task") -> Text:
2 """Calculate common unit for completed and total."""
3 completed = int(task.completed)
4
5 unit_and_suffix_calculation_base = (
6 int(task.total) if task.total is not None else completed
7 )
8 if self.binary_units:
9 unit, suffix = filesize.pick_unit_and_suffix(
10 unit_and_suffix_calculation_base,
11 ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
12 1024,
13 )
14 else:
15 unit, suffix = filesize.pick_unit_and_suffix(
16 unit_and_suffix_calculation_base,
17 ["bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
18 1000,
19 )
20 precision = 0 if unit == 1 else 1
21
22 completed_ratio = completed / unit
23 completed_str = f"{completed_ratio:,.{precision}f}"
24
25 if task.total is not None:
26 total = int(task.total)
27 total_ratio = total / unit
28 total_str = f"{total_ratio:,.{precision}f}"
29 else:
30 total_str = "?"
31
32 download_status = f"{completed_str}/{total_str} {suffix}"
33 download_text = Text(download_status, style="progress.download")
34 return download_text
Path 2: 1 calls (0.12)
Task (1)
Text (1)
1def render(self, task: "Task") -> Text:
2 """Calculate common unit for completed and total."""
3 completed = int(task.completed)
4
5 unit_and_suffix_calculation_base = (
6 int(task.total) if task.total is not None else completed
7 )
8 if self.binary_units:
9 unit, suffix = filesize.pick_unit_and_suffix(
10 unit_and_suffix_calculation_base,
11 ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
12 1024,
13 )
14 else:
15 unit, suffix = filesize.pick_unit_and_suffix(
16 unit_and_suffix_calculation_base,
17 ["bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
18 1000,
19 )
20 precision = 0 if unit == 1 else 1
21
22 completed_ratio = completed / unit
23 completed_str = f"{completed_ratio:,.{precision}f}"
24
25 if task.total is not None:
26 total = int(task.total)
27 total_ratio = total / unit
28 total_str = f"{total_ratio:,.{precision}f}"
29 else:
30 total_str = "?"
31
32 download_status = f"{completed_str}/{total_str} {suffix}"
33 download_text = Text(download_status, style="progress.download")
34 return download_text