Skip to content

Instantly share code, notes, and snippets.

@rshk
Created November 6, 2015 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rshk/131c2a63a6adcc07ecda to your computer and use it in GitHub Desktop.
Save rshk/131c2a63a6adcc07ecda to your computer and use it in GitHub Desktop.
import subprocess
import sys
flake8 = ['flake8'] + sys.argv[1:]
proc = subprocess.Popen(flake8, stdout=subprocess.PIPE)
for line in proc.stdout:
filename, row, col, extra = [
x.strip().decode('utf8')
for x in line.split(b':', 3)]
msgcolor = '2'
if extra[0] == 'E':
msgcolor = '1'
elif extra[0] == 'F':
msgcolor = '5'
elif extra[0] == 'W':
msgcolor = '3'
print("\x1b[1m{}\x1b[0;32m:{}\x1b[0;33m:{}\x1b[0m \x1b[3{}m{}\x1b[0m"
.format(filename, row, col, msgcolor, extra))
blame = subprocess.check_output(
['git', 'blame', filename, '-L', '{0},{0}'.format(row)]
).strip().decode('utf8')
print(' {}'.format(blame))
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment