Example #1
0
def cmd_check_indentation(filenames):
    """Run pylint indendation check on filenames."""
    errors_found_p = False
    print_heading('Checking Python indentation...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen(['pylint', '--rcfile=/dev/null',
                                    PYLINT_VERSION.startswith('0') and \
                                      '--output-format=parseable' or \
                                      '--msg-template={path}:{line}:' +
                                      ' [{msg_id}({symbol}), {obj}] {msg}',
                                    '--reports=n', filename],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        process_output, process_error = process.communicate()
        if process_error:
            errors_found_p = True
            print("[ERROR]", process_error)
        for line in process_output.split('\n'): # pylint: disable=E1103
            if 'indent' in line:
                out += line + '\n'
        if out:
            errors_found_p = True
            print(out)
    return errors_found_p
Example #2
0
def cmd_check_indentation(filenames):
    """Run pylint indendation check on filenames."""
    errors_found_p = False
    print_heading('Checking Python indentation...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen([
            'pylint', '--rcfile=/dev/null',
            PYLINT_VERSION.startswith('0') and '--output-format=parseable'
            or '--msg-template={path}:{line}:' +
            ' [{msg_id}({symbol}), {obj}] {msg}', '--reports=n', filename
        ],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        process_output, process_error = process.communicate()
        if process_error:
            errors_found_p = True
            print "[ERROR]", process_error
        for line in process_output.split('\n'):  # pylint: disable=E1103
            if 'indent' in line:
                out += line + '\n'
        if out:
            errors_found_p = True
            print out
    return errors_found_p
Example #3
0
def cmd_check_variables(filenames):
    """Run pylint variable check on filenames."""
    errors_found_p = False
    print_heading('Checking Python variables...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen(['pylint', '--rcfile=/dev/null',
                                    PYLINT_VERSION.startswith('0') and \
                                      '--output-format=parseable' or \
                                      '--msg-template={path}:{line}:' +
                                      ' [{msg_id}({symbol}), {obj}] {msg}',
                                    '--reports=n', filename],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        pylint_output, pylint_error = process.communicate()
        if pylint_error:
            errors_found_p = True
            print("[ERROR]", pylint_error)
        for line in pylint_output.split('\n'): # pylint: disable=E1103
            if '; [F' in line or ': [E' in line or ': [W' in line:
                if 'variable' in line or \
                   'name' in line or \
                   'global' in line or \
                   'Unused' in line or \
                   'Redefining' in line:
                    out += line + '\n'
        if out:
            errors_found_p = True
            print(out)
    return errors_found_p
Example #4
0
def cmd_check_variables(filenames):
    """Run pylint variable check on filenames."""
    errors_found_p = False
    print_heading('Checking Python variables...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen([
            'pylint', '--rcfile=/dev/null',
            PYLINT_VERSION.startswith('0') and '--output-format=parseable'
            or '--msg-template={path}:{line}:' +
            ' [{msg_id}({symbol}), {obj}] {msg}', '--reports=n', filename
        ],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        pylint_output, pylint_error = process.communicate()
        if pylint_error:
            errors_found_p = True
            print "[ERROR]", pylint_error
        for line in pylint_output.split('\n'):  # pylint: disable=E1103
            if '; [F' in line or ': [E' in line or ': [W' in line:
                if 'variable' in line or \
                   'name' in line or \
                   'global' in line or \
                   'Unused' in line or \
                   'Redefining' in line:
                    out += line + '\n'
        if out:
            errors_found_p = True
            print out
    return errors_found_p
Example #5
0
def get_pylint_results(filename):
    """
    Run pylint and return the tuple of (nb_missing_docstrings, score,
    nb_msg_convention, nb_msg_refactor, nb_msg_warning, nb_msg_error,
    nb_msg_fatal) for FILENAME.  If score cannot be detected, print an
    error and return (-999999999, -999999999, 0, 0, 0, 0, 0).
    """
    process = subprocess.Popen(['pylint',
                                PYLINT_VERSION.startswith('0') and \
                                  '--output-format=parseable' or \
                                  '--msg-template={path}:{line}:' +
                                  ' [{msg_id}({symbol}), {obj}] {msg}',
                                '--rcfile=/dev/null',
                                filename],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)

    pylint_output, pylint_error = process.communicate()
    if pylint_error:
        print("[ERROR]", pylint_error)

    # detect number of missing docstrings:
    nb_missing_docstrings = pylint_output.count("] Missing docstring")

    # detect pylint score:
    pylint_score = -999999999
    pylint_score_matched = re.search(r'Your code has been rated at ' \
                                     '([0-9\.\-]+)\/10', pylint_output)
    if pylint_score_matched:
        pylint_score = pylint_score_matched.group(1)
    else:
        print("ERROR: cannot detect pylint score for %s" % filename)

    # detect pylint messages
    nb_msg_convention = pylint_output.count(": [C")
    nb_msg_refactor = pylint_output.count(": [R")
    nb_msg_warning = pylint_output.count(": [W")
    nb_msg_error = pylint_output.count(": [E")
    nb_msg_fatal = pylint_output.count(": [F")

    # return results:
    return (nb_missing_docstrings, float(pylint_score),
            nb_msg_convention, nb_msg_refactor, nb_msg_warning,
            nb_msg_error, nb_msg_fatal)
Example #6
0
def get_pylint_results(filename):
    """
    Run pylint and return the tuple of (nb_missing_docstrings, score,
    nb_msg_convention, nb_msg_refactor, nb_msg_warning, nb_msg_error,
    nb_msg_fatal) for FILENAME.  If score cannot be detected, print an
    error and return (-999999999, -999999999, 0, 0, 0, 0, 0).
    """
    process = subprocess.Popen([
        'pylint',
        PYLINT_VERSION.startswith('0') and '--output-format=parseable' or
        '--msg-template={path}:{line}:' + ' [{msg_id}({symbol}), {obj}] {msg}',
        '--rcfile=/dev/null', filename
    ],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)

    pylint_output, pylint_error = process.communicate()
    if pylint_error:
        print "[ERROR]", pylint_error

    # detect number of missing docstrings:
    nb_missing_docstrings = pylint_output.count("] Missing docstring")

    # detect pylint score:
    pylint_score = -999999999
    pylint_score_matched = re.search(
        r'Your code has been rated at '
        '([0-9\.\-]+)\/10', pylint_output)
    if pylint_score_matched:
        pylint_score = pylint_score_matched.group(1)
    else:
        print "ERROR: cannot detect pylint score for %s" % filename

    # detect pylint messages
    nb_msg_convention = pylint_output.count(": [C")
    nb_msg_refactor = pylint_output.count(": [R")
    nb_msg_warning = pylint_output.count(": [W")
    nb_msg_error = pylint_output.count(": [E")
    nb_msg_fatal = pylint_output.count(": [F")

    # return results:
    return (nb_missing_docstrings, float(pylint_score), nb_msg_convention,
            nb_msg_refactor, nb_msg_warning, nb_msg_error, nb_msg_fatal)
Example #7
0
def cmd_check_errors(filenames):
    """Run pylint error check on filenames."""
    errors_found_p = False
    print_heading('Checking Python errors...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen(['pylint', '--rcfile=/dev/null',
                                    PYLINT_VERSION.startswith('0') and \
                                      '--output-format=parseable' or \
                                      '--msg-template={path}:{line}:' +
                                      ' [{msg_id}({symbol}), {obj}] {msg}',
                                    '--errors-only', filename],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        out, err = process.communicate()
        if err:
            errors_found_p = True
            print("[ERROR]", err)
        if out:
            errors_found_p = True
            print(out)
    return errors_found_p
Example #8
0
def cmd_check_errors(filenames):
    """Run pylint error check on filenames."""
    errors_found_p = False
    print_heading('Checking Python errors...')
    for filename in filenames:
        out = ''
        process = subprocess.Popen([
            'pylint', '--rcfile=/dev/null',
            PYLINT_VERSION.startswith('0') and '--output-format=parseable'
            or '--msg-template={path}:{line}:' +
            ' [{msg_id}({symbol}), {obj}] {msg}', '--errors-only', filename
        ],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        out, err = process.communicate()
        if err:
            errors_found_p = True
            print "[ERROR]", err
        if out:
            errors_found_p = True
            print out
    return errors_found_p