src/pybel/cli.py
def echo_warnings_via_pager(warnings: List[WarningTuple], sep: str = '\t') -> None:
    """Output the warnings from a BEL graph with Click and the system's pager."""
    # Exit if no warnings
    if not warnings:
        click.echo('Congratulations! No warnings.')
        sys.exit(0)

    max_line_width = max(
        len(str(exc.line_number))
        for _, exc, _ in warnings
    )

    max_warning_width = max(
        len(exc.__class__.__name__)
        for _, exc, _ in warnings
    )

    s1 = '{:>' + str(max_line_width) + '}' + sep
    s2 = '{:>' + str(max_warning_width) + '}' + sep

    def _make_line(path: str, exc: BELParserWarning):
        s = click.style(path, fg='cyan') + sep
        s += click.style(s1.format(exc.line_number), fg='blue', bold=True)
        s += click.style(
            s2.format(exc.__class__.__name__),
            fg=('red' if exc.__class__.__name__.endswith('Error') else 'yellow'),
        )
        s += click.style(exc.line, bold=True) + sep
        s += click.style(str(exc))
        return s

    click.echo_via_pager(
        '\n'.join(
            _make_line(path, exc)
            for path, exc, _ in warnings
        ),
    )
Output the warnings from a BEL graph with Click and the system's pager.
Output the warnings from a BEL graph with Click and the system's pager.
Output the warnings from a BEL graph with Click and the system ' s pager .
def echo_warnings_via_pager(warnings: List[WarningTuple], sep: str = '\t') -> None:
    if not warnings:
        click.echo('Congratulations! No warnings.')
        sys.exit(0)
    max_line_width = max(
        len(str(exc.line_number))
        for _, exc, _ in warnings
    )
    max_warning_width = max(
        len(exc.__class__.__name__)
        for _, exc, _ in warnings
    )
    s1 = '{:>' + str(max_line_width) + '}' + sep
    s2 = '{:>' + str(max_warning_width) + '}' + sep
    def _make_line(path: str, exc: BELParserWarning):
        s = click.style(path, fg='cyan') + sep
        s += click.style(s1.format(exc.line_number), fg='blue', bold=True)
        s += click.style(
            s2.format(exc.__class__.__name__),
            fg=('red' if exc.__class__.__name__.endswith('Error') else 'yellow'),
        )
        s += click.style(exc.line, bold=True) + sep
        s += click.style(str(exc))
        return s
    click.echo_via_pager(
        '\n'.join(
            _make_line(path, exc)
            for path, exc, _ in warnings
        ),
    )
def echo_warnings_via_pager ( warnings : List [ WarningTuple ] , sep : str = '\t' ) -> None : if not warnings : click . echo ( 'Congratulations! No warnings.' ) sys . exit ( 0 ) max_line_width = max ( len ( str ( exc . line_number ) ) for _ , exc , _ in warnings ) max_warning_width = max ( len ( exc . __class__ . __name__ ) for _ , exc , _ in warnings ) s1 = '{:>' + str ( max_line_width ) + '}' + sep s2 = '{:>' + str ( max_warning_width ) + '}' + sep def _make_line ( path : str , exc : BELParserWarning ) : s = click . style ( path , fg = 'cyan' ) + sep s += click . style ( s1 . format ( exc . line_number ) , fg = 'blue' , bold = True ) s += click . style ( s2 . format ( exc . __class__ . __name__ ) , fg = ( 'red' if exc . __class__ . __name__ . endswith ( 'Error' ) else 'yellow' ) , ) s += click . style ( exc . line , bold = True ) + sep s += click . style ( str ( exc ) ) return s click . echo_via_pager ( '\n' . join ( _make_line ( path , exc ) for path , exc , _ in warnings ) , )
Output the warnings from a BEL graph with Click and the system's pager.
Output the warnings from a BEL graph with Click and the system ' s pager .
"""Output the warnings from a BEL graph with Click and the system's pager.""" # Exit if no warnings
warnings
List[WarningTuple]
sep
str