Skip to content

Instantly share code, notes, and snippets.

@dhermes
Last active August 29, 2015 14:15
Show Gist options
  • Save dhermes/d193bf8e9a14f24d8750 to your computer and use it in GitHub Desktop.
Save dhermes/d193bf8e9a14f24d8750 to your computer and use it in GitHub Desktop.
# As of github.com/GoogleCloudPlatform/gcloud-python/tree/56f60bb94b313c397f5aeadee1f0e1f6e5b5290c
import os
import subprocess
from run_pylint import get_files_for_linting
from run_pylint import get_python_files
all_files, _ = get_files_for_linting(allow_limited=False)
library_files, _, _ = get_python_files(all_files=all_files)
filenames = [filename for filename in library_files
if os.path.exists(filename)]
rc_flag = '--rcfile=pylintrc_default'
pylint_shell_command = ['pylint', '--py3k', rc_flag] + filenames
proc = subprocess.Popen(pylint_shell_command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
status = proc.wait()
print 'Status code:'
print status
print '-' * 40
py3k_lint_output = proc.stdout.read()
py3k_lint_lines = py3k_lint_output.rstrip().split('\n')
py3k_lint_error_lines = [line for line in py3k_lint_lines
if not line.startswith('************* Module')]
def get_error_message(line):
err_type, _, content = line.split(':', 2)
if err_type not in ('E', 'W'):
raise ValueError(line)
return content.strip()
py3k_lint_errors = [get_error_message(line) for line in py3k_lint_error_lines]
unique_errors = set(py3k_lint_errors)
print 'Actual Errors (%d):' % (len(py3k_lint_errors),)
print '-' * 40
for line in unique_errors:
print '%s (%d)' % (line, py3k_lint_errors.count(line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment