Ejemplo n.º 1
0
def lint(config, root):
    """Find and return the 'lint' function for the external linter named in the
    LINTER global variable.

    This will automatically pass in the 'config' and 'root' arguments if not
    specified.
    """
    try:
        func = findobject(config['payload'])
    except (ImportError, ValueError):
        pytest.fail("could not resolve a lint function from '{}'".format(config['payload']))

    ResultSummary.root = root

    def wrapper(paths, config=config, root=root, collapse_results=False, **lintargs):
        results = func(paths, config, root=root, **lintargs)
        if not collapse_results:
            return results

        ret = defaultdict(list)
        for r in results:
            ret[r.path].append(r)
        return ret

    return wrapper
Ejemplo n.º 2
0
def lint(config, root):
    """Find and return the 'lint' function for the external linter named in the
    LINTER global variable.

    This will automatically pass in the 'config' and 'root' arguments if not
    specified.
    """
    try:
        func = findobject(config["payload"])
    except (ImportError, ValueError):
        pytest.fail(
            "could not resolve a lint function from '{}'".format(config["payload"])
        )

    ResultSummary.root = root

    def wrapper(paths, config=config, root=root, collapse_results=False, **lintargs):
        logger.setLevel(logging.DEBUG)
        lintargs["log"] = logging.LoggerAdapter(
            logger, {"lintname": config.get("name"), "pid": os.getpid()}
        )
        results = func(paths, config, root=root, **lintargs)

        if isinstance(results, (list, tuple)):
            results = sorted(results)

        if not collapse_results:
            return results

        ret = defaultdict(list)
        for r in results:
            ret[r.relpath].append(r)
        return ret

    return wrapper
Ejemplo n.º 3
0
def lint_wrapper(paths, config, **lintargs):
    _apply_global_excludes(lintargs['root'], config)

    payload = findobject(config['wraps'])
    config['payload'] = config['wraps']
    del config['wraps']

    return payload(paths, config, **lintargs)
Ejemplo n.º 4
0
def lint_wrapper(paths, config, **lintargs):
    _apply_global_excludes(lintargs["root"], config)

    payload = findobject(config["wraps"])
    config["payload"] = config["wraps"]
    del config["wraps"]

    return payload(paths, config, **lintargs)
Ejemplo n.º 5
0
def run_setup(config):
    """Make sure that if the linter named in the LINTER global variable has a
    setup function, it gets called before running the tests.
    """
    if "setup" not in config:
        return

    func = findobject(config["setup"])
    func(build.topsrcdir)
Ejemplo n.º 6
0
def run_setup(config):
    """Make sure that if the linter named in the LINTER global variable has a
    setup function, it gets called before running the tests.
    """
    if "setup" not in config:
        return

    log = logging.LoggerAdapter(logger, {
        "lintname": config.get("name"),
        "pid": os.getpid()
    })

    func = findobject(config["setup"])
    func(
        build.topsrcdir,
        virtualenv_manager=build.virtualenv_manager,
        virtualenv_bin_path=build.virtualenv_manager.bin_path,
        log=log,
    )
Ejemplo n.º 7
0
def structuredlog_lint(config, root, logger=None):
    """Find and return the 'lint' function for the external linter named in the
    LINTER global variable. This variant of the lint function is for linters that
    use the 'structuredlog' type.

    This will automatically pass in the 'config' and 'root' arguments if not
    specified.
    """
    try:
        func = findobject(config["payload"])
    except (ImportError, ValueError):
        pytest.fail("could not resolve a lint function from '{}'".format(
            config["payload"]))

    ResultSummary.root = root

    if not logger:
        logger = structured_logger()

    def wrapper(
        paths,
        config=config,
        root=root,
        logger=logger,
        collapse_results=False,
        **lintargs,
    ):
        lintargs["log"] = logging.LoggerAdapter(logger, {
            "lintname": config.get("name"),
            "pid": os.getpid()
        })
        results = func(paths, config, root=root, logger=logger, **lintargs)
        if not collapse_results:
            return results

        ret = defaultdict(list)
        for r in results:
            ret[r.path].append(r)
        return ret

    return wrapper