Edit on GitHub

sqlmesh.utils.rich

 1import typing as t
 2
 3from rich.console import Console
 4from rich.progress import Column, ProgressColumn, Task, Text
 5from rich.theme import Theme
 6
 7theme = Theme(
 8    {
 9        "added": "green",
10        "removed": "red",
11        "direct": "magenta",  # directly modified
12        "indirect": "yellow",  # indirectly modified
13        "metadata": "cyan",  # metadata updated
14    }
15)
16
17console = Console(theme=theme)
18
19
20class BatchColumn(ProgressColumn):
21    """Renders completed count/total, "pending".
22
23    Space pads the completed count so that progress length does not change as task progresses
24    past powers of 10.
25
26    Source: https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.MofNCompleteColumn
27
28    Args:
29        separator: Text to separate completed and total values. Defaults to "/".
30    """
31
32    def __init__(self, separator: str = "/", table_column: t.Optional[Column] = None):
33        self.separator = separator
34        super().__init__(table_column=table_column)
35
36    def render(self, task: Task) -> Text:
37        """Show completed count/total, "pending"."""
38        total = int(task.total) if task.total is not None else "?"
39        completed = int(task.completed)
40
41        if completed == 0 and task.total is not None and task.total > 0:
42            return Text("pending", style="progress.download")
43
44        total_width = len(str(total))
45        return Text(
46            f"{completed:{total_width}d}{self.separator}{total}",
47            style="progress.download",
48        )
class BatchColumn(rich.progress.ProgressColumn):
21class BatchColumn(ProgressColumn):
22    """Renders completed count/total, "pending".
23
24    Space pads the completed count so that progress length does not change as task progresses
25    past powers of 10.
26
27    Source: https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.MofNCompleteColumn
28
29    Args:
30        separator: Text to separate completed and total values. Defaults to "/".
31    """
32
33    def __init__(self, separator: str = "/", table_column: t.Optional[Column] = None):
34        self.separator = separator
35        super().__init__(table_column=table_column)
36
37    def render(self, task: Task) -> Text:
38        """Show completed count/total, "pending"."""
39        total = int(task.total) if task.total is not None else "?"
40        completed = int(task.completed)
41
42        if completed == 0 and task.total is not None and task.total > 0:
43            return Text("pending", style="progress.download")
44
45        total_width = len(str(total))
46        return Text(
47            f"{completed:{total_width}d}{self.separator}{total}",
48            style="progress.download",
49        )

Renders completed count/total, "pending".

Space pads the completed count so that progress length does not change as task progresses past powers of 10.

Source: https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.MofNCompleteColumn

Arguments:
  • separator: Text to separate completed and total values. Defaults to "/".
BatchColumn( separator: str = '/', table_column: Union[rich.table.Column, NoneType] = None)
33    def __init__(self, separator: str = "/", table_column: t.Optional[Column] = None):
34        self.separator = separator
35        super().__init__(table_column=table_column)
def render(self, task: rich.progress.Task) -> rich.text.Text:
37    def render(self, task: Task) -> Text:
38        """Show completed count/total, "pending"."""
39        total = int(task.total) if task.total is not None else "?"
40        completed = int(task.completed)
41
42        if completed == 0 and task.total is not None and task.total > 0:
43            return Text("pending", style="progress.download")
44
45        total_width = len(str(total))
46        return Text(
47            f"{completed:{total_width}d}{self.separator}{total}",
48            style="progress.download",
49        )

Show completed count/total, "pending".

Inherited Members
rich.progress.ProgressColumn
get_table_column