Exemple #1
0
 def __init__(
     self,
     renderable,
     box=box.Box("────\n    \n────\n    \n────\n────\n    \n────\n"),
     **kwargs,
 ):
     super(ConfigurablePanel, self).__init__(renderable, box, **kwargs)
Exemple #2
0
def parse_md_table(match, tables_memo):
    from rich.console import Console
    from rich.table import Table
    from rich.style import Style
    from rich.align import Align
    from rich import box
    import re
    [table_header, table_body, columns] = split_md_table(match.group(2))
    b = box.Box('    \n    \n══╪═\n    \n┈┈┼┈\n┈┈┼┈\n    \n    ')
    table = Table(box=b,
                  show_header=False,
                  show_edge=False,
                  border_style=Style(color='#222222'))
    for col_align in columns:
        table.add_column(None, justify=col_align)
    sty_header = Style(bgcolor='blue', color='#000000', bold=True)
    sty_odd = Style(bgcolor="#111111", color='white')
    sty_even = Style(bgcolor="#222222", color='white')
    for row in table_header:
        row = map(Align.center, row)
        table.add_row(*row, style=sty_header)
    num = 0
    for row in table_body:
        num += 1
        style = sty_even if (num % 2 == 0) else sty_odd
        table.add_row(*row, style=style)

    console = Console(width=70)
    with console.capture() as capture:
        console.print(table)
    formated_text = '\n'.join(capture.get().split('\n')[0:-1])
    before = '' if match.group(1) == '\n\n' else '\n'
    after = '  ' if match.group(3) == '\n' else '  \n'
    tables_memo.append(before + formated_text)
    return match.group(1) + \
           '<#MD-TABLE-'+str(len(tables_memo)-1)+'#>' + after + \
           match.group(3)
Exemple #3
0
from rich.console import Console
from rich.table import Table
from rich.text import Text

from modelci.types.models import MLModel

console = Console()

status_mapper = {
    'Pass': '******',
    'Running': '[yellow]🚧[/yellow] Running',
    'Fail': '[red]✖[/red] Fail',
    'Unknown': '[grey]💔[/grey] Unknown'
}

BOX_NO_BORDER = box.Box('\n'.join([' ' * 4] * 8))


def single_model_view(model: Optional[dict], top=False):
    if model is None:
        return ''

    if top:
        model_name = f'[bold]{model["name"]}[/bold]'
    else:
        model_name = model['name']

    return (
        model['id'],
        model_name,
        model['framework'],
def print_modules(modules: dict, module_type: str, reverse_config_usage: dict, snake_storage: snake_utils.SnakeStorage,
                  print_params: bool = False):
    """Print module information."""
    custom_annotations = snake_storage.all_custom_annotators

    # Box styles
    left_line = box.Box("    \n┃   \n┃   \n┃   \n┃   \n┃   \n┃   \n    ")
    minimal = box.Box("    \n  │ \n╶─┼╴\n  │ \n╶─┼╴\n╶─┼╴\n  │ \n    \n")
    box_style = minimal

    # Module type header
    print()
    console.print(f"  [b]{module_type.upper()}[/b]", style="reverse", justify="left")  # 'justify' to fill entire width
    print()

    for i, module_name in enumerate(sorted(modules)):
        if i:
            console.print(Rule())

        # Module name header
        console.print(f"\n[bright_black]:[/][dim]:[/]: [b]{module_name.upper()}[/b]\n")

        # Module description
        description = None
        if registry.modules[module_name].description:
            description = registry.modules[module_name].description
        elif module_name.startswith("custom."):
            description = get_custom_module_description(module_name)
        if description:
            console.print(Padding(description, (0, 4, 1, 4)))

        for f_name in sorted(modules[module_name]):
            # Function name and description
            f_desc = modules[module_name][f_name]["description"]
            console.print(Padding(Panel(f"[b]{f_name.upper()}[/b]\n[i]{f_desc}[/i]", box=left_line, padding=(0, 1),
                                        border_style="bright_green"), (0, 2)))

            # Get parameters. Always print these for custom annotations
            params = modules[module_name][f_name].get("params", {})
            custom_params = None
            if custom_annotations.get(module_name, {}).get(f_name):
                custom_params = custom_annotations[module_name][f_name].get("params", {})
                params = custom_params

            # Annotations
            f_anns = modules[module_name][f_name].get("annotations", {})
            if f_anns:
                this_box_style = box_style if any(a[1] for a in f_anns) else box.SIMPLE
                table = Table(title="[b]Annotations[/b]", box=this_box_style, show_header=False,
                              title_justify="left", padding=(0, 2), pad_edge=False, border_style="bright_black")
                table.add_column(no_wrap=True)
                table.add_column()
                for f_ann in sorted(f_anns):
                    table.add_row("• " + f_ann[0].name + (
                        f"\n  [i dim]class:[/] <{f_ann[0].cls}>" if f_ann[0].cls else ""),
                        f_ann[1] or "")
                console.print(Padding(table, (0, 0, 0, 4)))
            elif custom_params:
                # Print info about custom annotators
                this_box_style = box_style if any(a[1] for a in f_anns) else box.SIMPLE
                table = Table(title="[b]Annotations[/b]", box=this_box_style, show_header=False,
                              title_justify="left", padding=(0, 2), pad_edge=False, border_style="bright_black")
                table.add_column()
                table.add_row("In order to use this annotator you first need to declare it in the 'custom_annotations' "
                              "section of your corpus configuration and specify its arguments.")
                console.print(Padding(table, (0, 0, 0, 4)))

            # Config variables
            f_config = reverse_config_usage.get(f"{module_name}:{f_name}")
            if f_config:
                console.print()
                table = Table(title="[b]Configuration variables used[/b]", box=box_style, show_header=False,
                              title_justify="left", padding=(0, 2), pad_edge=False, border_style="bright_black")
                table.add_column(no_wrap=True)
                table.add_column()
                for config_key in sorted(f_config):
                    table.add_row("• " + config_key[0], config_key[1] or "")
                console.print(Padding(table, (0, 0, 0, 4)))

            # Arguments
            if (print_params and params) or custom_params:
                table = Table(title="[b]Arguments[/b]", box=box_style, show_header=False, title_justify="left",
                              padding=(0, 2), pad_edge=False, border_style="bright_black")
                table.add_column(no_wrap=True)
                table.add_column()
                for p, (default, typ, li, optional) in params.items():
                    opt_str = "(optional) " if optional else ""
                    typ_str = "list of " + typ.__name__ if li else typ.__name__
                    def_str = f", default: {repr(default)}" if default is not None else ""
                    table.add_row("• " + p, f"{opt_str}{typ_str}{def_str}")
                console.print(Padding(table, (0, 0, 0, 4)))
            print()