コード例 #1
0
ファイル: pick-python.py プロジェクト: d00h/kakoune-pick
def command_grep(args):
    recurse = not (args.filename and os.path.isfile(args.filename))
    xpath = XPATH[args.target]
    astpath.search(directory=args.filename or '.',
                   expression=xpath,
                   recurse=recurse,
                   print_matches=True)
コード例 #2
0
def main() -> NoReturn:
    """Check for ``self.generic_visit()`` in all visit methods."""
    if len(sys.argv) == 1:
        report('Please provide path to search in!')

    matches = astpath.search(sys.argv[1], PATTERN, print_matches=False)

    if not len(matches):
        exit(OK_CODE)  # noqa: WPS421

    report()
    report('"self.generic_visit(node)" should be last statement here:')

    for fn, line in matches:
        with open(fn, 'r') as fp:
            lines = fp.read().splitlines()
            report(
                '\t{0}:{1}\n\t{2}'.format(
                    fn, line,
                    highlight(
                        lines[line - 1],
                        PythonLexer(),
                        Terminal256Formatter(),
                    )), )

    exit(FAIL_CODE)  # noqa: WPS421
コード例 #3
0
def _get_setup_files(*, path: typing.Union[str, pathlib.Path]):
    """
    Returns relative paths with use of Startup object
    """
    logger.info("finding setup files")
    res = astpath.search(path, "//Call/func/*[@id='Setup' or @attr='Setup']")

    return set(s[0] for s in res)
コード例 #4
0
def _get_endpoint_files(
        path: typing.Union[str, pathlib.Path] = ".") -> typing.Iterable[str]:
    """
    Returns relative paths with use of Route object
    """
    logger.debug("finding router files")
    res = astpath.search(path, "//Call/func/*[@id='Router' or @attr='Router']")

    return set(s[0] for s in res)
コード例 #5
0
ファイル: pick-python.py プロジェクト: d00h/kakoune-pick
def command_xpath(args):
    recurse = not (args.filename and os.path.isfile(args.filename))
    astpath.search(directory=args.filename or '.',
                   expression=args.xpath,
                   recurse=recurse,
                   print_matches=True)
コード例 #6
0
PATTERN = '''
//ClassDef[contains(bases, Name[@id='BaseNodeVisitor'])]/body
/FunctionDef[re:match('visit_.*', @name)
and not(child::body/Expr[last()]/value/Call/func
/Attribute[@attr='generic_visit'])]
'''  # noqa: Q001

# This is needed to stop linter from spewing WPS421 errors.
my_print = print

if __name__ == '__main__':
    if len(sys.argv) == 1:
        my_print('Please provide path to search in!')

    matches = astpath.search(sys.argv[1], PATTERN, print_matches=False)

    if not len(matches):
        exit(OK_CODE)  # noqa: WPS421

    my_print()
    my_print('"self.generic_visit(node)" should be last statement here:')

    for fn, line in matches:
        with open(fn, 'r') as fp:
            source = fp.read()
            lines = source.splitlines()
            highlighted = highlight(
                lines[line - 1],
                PythonLexer(),
                Terminal256Formatter(),