Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Created April 11, 2019 21:31
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 AlexArcPy/4d15c61d6b7fe8e1ae7af83ad5a30d0c to your computer and use it in GitHub Desktop.
Save AlexArcPy/4d15c61d6b7fe8e1ae7af83ad5a30d0c to your computer and use it in GitHub Desktop.
Flake8 snippets
# flake8 > C:/Temp/StyleGuide.csv
import os
os.chdir('C:/Temp')
import pandas as pd
for errors_file in ['StyleGuide1.csv', 'StyleGuide2.csv']:
df = pd.read_csv(errors_file, sep=':')
df.columns = ['FilePath', 'LineNo', 'ColumnNo', 'ErrorMessage']
df = df[['FilePath', 'LineNo', 'ColumnNo', 'ErrorMessage']]
df['ErrorCode'] = df['ErrorMessage'].str[:5]
df['ErrorMessage'] = df['ErrorMessage'].str[6:]
agg = df.groupby(['ErrorCode', 'ErrorMessage']).size().reset_index(name='Count')
agg.sort_values(['Count', 'ErrorCode'], inplace=True)
agg.to_csv("_agg" + errors_file, index=False)
# get files that have been changed in the 5 last commits
$ git diff HEAD HEAD~5 --name-only > C:/Temp/diff_files.txt
# feed each file to flake8
$ cat C:/Temp/diff_files.txt | grep .py | xargs flake8 --filename
# single-line command
git diff HEAD HEAD~5 --name-only | grep .py | xargs flake8 --filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment