Beispiel #1
0
def execute_pylint(project, logger):
    logger.info("Executing pylint on project sources")

    command_and_arguments = ["pylint"] + project.get_property("pylint_options")
    result_tuple = execute_tool_on_modules(project, "pylint", command_and_arguments, True)

    if project.get_property("pylint_break_build"):
        report_file = result_tuple[1]  # access by position to avoid changing mocking behaviour

        warnings = [line
                    for line in read_file(report_file)
                    if line.find('.py:') >= 0]
        warning_count = len(warnings)

        if warning_count > 0:
            message = "Pylint found {} warning(s).".format(warning_count)
            logger.error(message)
            raise BuildFailedException(message)
def execute_pylint(project, logger):
    logger.info("Executing pylint on project sources")

    command_and_arguments = ["pylint"] + project.get_property("pylint_options")
    result_tuple = execute_tool_on_modules(project, "pylint",
                                           command_and_arguments, True)

    if project.get_property("pylint_break_build"):
        report_file = result_tuple[
            1]  # access by position to avoid changing mocking behaviour

        warnings = [
            line for line in read_file(report_file) if line.find('.py:') >= 0
        ]
        warning_count = len(warnings)

        if warning_count > 0:
            message = "Pylint found {} warning(s).".format(warning_count)
            logger.error(message)
            raise BuildFailedException(message)
Beispiel #3
0
def execute_pychecker(project, logger):
    command_line = build_command_line(project)
    logger.info("Executing pychecker on project sources: %s" % (' '.join(command_line)))

    _, report_file = execute_tool_on_modules(project, "pychecker", command_line, True)

    warnings = read_file(report_file)

    report = parse_pychecker_output(project, warnings)
    project.write_report("pychecker.json", render_report(report.to_json_dict()))

    if len(warnings) != 0:
        logger.warn("Found %d warning%s produced by pychecker. See %s for details.",
                    len(warnings),
                    "s" if len(warnings) != 1 else "",
                    report_file)

        threshold = project.get_property("pychecker_break_build_threshold")

        if project.get_property("pychecker_break_build") and len(warnings) > threshold:
            raise BuildFailedException("Found warnings produced by pychecker")
Beispiel #4
0
def execute_pychecker(project, logger):
    command_line = build_command_line(project)
    logger.info("Executing pychecker on project sources: %s" %
                (' '.join(command_line)))

    _, report_file = execute_tool_on_modules(project, "pychecker",
                                             command_line, True)

    warnings = read_file(report_file)

    report = parse_pychecker_output(project, warnings)
    project.write_report("pychecker.json",
                         render_report(report.to_json_dict()))

    if len(warnings) != 0:
        logger.warn(
            "Found %d warning%s produced by pychecker. See %s for details.",
            len(warnings), "s" if len(warnings) != 1 else "", report_file)

        threshold = project.get_property("pychecker_break_build_threshold")

        if project.get_property(
                "pychecker_break_build") and len(warnings) > threshold:
            raise BuildFailedException("Found warnings produced by pychecker")
Beispiel #5
0
def execute_pylint(project, logger):
    logger.info("Executing pylint on project sources")

    command_and_arguments = ["pylint"] + project.get_property("pylint_options")
    pylint_output_file_path = execute_tool_on_modules(project, "pylint",
                                                      command_and_arguments,
                                                      True)[1]

    with open(pylint_output_file_path, 'r') as f:
        file_content = f.read().splitlines()

    module_name = ''
    pylint_score = 0
    pylint_change = 0
    errors = 0
    errors_info = ''
    warnings = 0
    warnings_info = ''
    show_info_messages = project.get_property('pylint_show_info_messages')
    show_warning_messages = project.get_property(
        'pylint_show_warning_messages')
    for line in file_content:
        if line.startswith('************* Module'):
            module_name = line.split(' ')[2]

        if line.startswith('E:') or line.startswith('F:'):
            logger.error('Pylint: Module %s: ' % module_name + line)
            errors += 1

        if show_warning_messages and line.startswith('W:'):
            logger.warn('Pylint: Module %s: ' % module_name + line)
            warnings += 1

        if show_info_messages and (line.startswith('C:')
                                   or line.startswith('R:')):
            logger.info('Pylint: Module %s: ' % module_name + line)

        if line.startswith('Your code has been rated at '):
            pylint_score = float(line.split(' ')[6].split('/')[0])
            pylint_change = float(line.split(' ')[10][:-1])

    if errors > 0:
        errors_info = ' / Errors: {}'.format(errors)

    if warnings > 0:
        warnings_info = ' / Warnings {}'.format(warnings)

    logger.info('Pylint ratio: {} / Pylint change: {}'.format(
        pylint_score, pylint_change) + errors_info + warnings_info)

    if errors > 0 and project.get_property('pylint_break_build_on_errors'):
        raise BuildFailedException(
            "Pylint: Building failed due to {} errors or fatal errors".format(
                errors))

    pylint_expected_score = project.get_property('pylint_score_threshold')
    pylint_expected_score_change = project.get_property(
        'pylint_score_change_threshold')
    if pylint_expected_score and pylint_score < pylint_expected_score:
        raise BuildFailedException(
            "Pylint: Building failed due to Pylint score({}) less then expected({})"
            .format(pylint_score, pylint_expected_score))
    if pylint_expected_score_change and pylint_change < pylint_expected_score_change:
        raise BuildFailedException(
            "Pylint: Building failed due to Pylint score decrease({}) higher then allowed({})"
            .format(pylint_change, pylint_expected_score_change))
Beispiel #6
0
def execute_pylint(project, logger):
    logger.info("Executing pylint on project sources")

    execute_tool_on_modules(project, "pylint", "pylint", True)
def execute_pylint(project, logger):
    logger.info("Executing pylint on project sources")

    command_and_arguments = ["pylint"] + project.get_property("pylint_options")
    execute_tool_on_modules(project, "pylint", command_and_arguments, True)