示例#1
0
 def __rich_console__(
         self,
         console: Console,
         options: ConsoleOptions  # noqa: U100
 ) -> RenderResult:
     for message, locations in self.grouped_warnings.items():
         yield from locations
         yield Padding.indent(message, 4)
     yield (
         "[bold red]♥[/bold red] " +
         "https://pytask-dev.rtdf.io/en/stable/how_to_guides/capture_warnings.html"
     )
示例#2
0
文件: toolbox.py 项目: jhegeman/ipbb
def check_depfile(env, verbose, toolset, component, depfile):
    '''Perform basic checks on dependency files'''

    lPackage, lComponent = component
    if depfile is None:
        depfile = basename(lComponent) + ".dep"

    lPathMaker = Pathmaker(env.srcdir, env._verbosity)

    try:
        lParser = DepFileParser(toolset, lPathMaker)
        lParser.parse(lPackage, lComponent, depfile)
    except OSError as lExc:
        raise click.ClickException(
            "Failed to parse dep file - '{}'".format(lExc))

    cprint()

    # N.B. Rest of this function is heavily based on implementation of 'dep report' command; assuming
    #   that output of these 2 commands does not significantly diverge, might make sense to implement
    #   command output in a separate function, that's invoked by both commands

    lCmdHeaders = [
        'path',
        'flags',
        'lib',
    ]  # ['path', 'flags', 'package', 'component', 'map', 'lib']
    lFilters = []

    lPrepend = re.compile('(^|\n)')
    if verbose:
        cprint('Parsed commands', style='blue')

        for k in lParser.commands:
            cprint(f"  + {k} ({len(lParser.commands[k])})")
            if not lParser.commands[k]:
                continue

            lCmdTable = Table(*lCmdHeaders,
                              title=f"{k} ({len(lParser.commands[k])})")
            for lCmd in lParser.commands[k]:
                lRow = [
                    relpath(lCmd.filepath, env.srcdir),
                    ','.join(lCmd.flags()),
                    lCmd.lib,
                ]

                if lFilters and not all(
                    [rxp.match(lRow[i]) for i, rxp in lFilters]):
                    continue

                lCmdTable.add_row(*lRow)

            cprint(Padding.indent(lCmdTable, 4))

        cprint('Resolved packages & components', style='blue')

        string = ''
        for pkg in sorted(lParser.packages):
            string += '  + %s (%d)\n' % (pkg, len(lParser.packages[pkg]))
            for cmp in sorted(lParser.packages[pkg]):
                string += '    > ' + str(cmp) + '\n'
        cprint(string)

    if lParser.unresolved_packages:
        cprint('Missing packages:', style='red')
        cprint(str(list(lParser.unresolved_packages)))

    lCNF = lParser.unresolved_components
    if lCNF:
        cprint('Missing components:', style='red')
        string = ''

        for pkg in sorted(lCNF):
            string += '+ %s (%d)\n' % (pkg, len(lCNF[pkg]))

            for cmp in sorted(lCNF[pkg]):
                string += '  > ' + str(cmp) + '\n'
        cprint(string)

    lFNF = lParser.unresolved_files
    if lFNF:
        cprint('Missing files:', style='red')

        lFNFTable = Table('path', 'included by')
        for pkg in sorted(lFNF):
            lCmps = lFNF[pkg]
            for cmp in sorted(lCmps):
                lPathExps = lCmps[cmp]
                for pathexp in sorted(lPathExps):

                    lFNFTable.add_row(
                        relpath(pathexp, env.srcdir),
                        '\n'.join([
                            relpath(src, env.srcdir)
                            for src in lPathExps[pathexp]
                        ]),
                    )
        cprint(Padding.indent(lFNFTable, 4))

    if lParser.unresolved_packages or lParser.unresolved_components or lParser.unresolved_files:
        raise click.ClickException(
            f"Cannot find 1 or more files referenced by depfile {lPathMaker.getPath(lPackage, lComponent, 'include', depfile)}"
        )
    elif not verbose:
        cprint(
            f"No errors found in depfile {lPathMaker.getPath(lPackage, lComponent, 'include', depfile)}"
        )
示例#3
0
def test_indent():
    indent_result = Padding.indent("test", 4)
    assert indent_result.top == 0
    assert indent_result.right == 0
    assert indent_result.bottom == 0
    assert indent_result.left == 4