Skip to content

Instantly share code, notes, and snippets.

@fcgomes92
Created March 8, 2018 12:17
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 fcgomes92/62008e5d440ae4117d49e93f477e0102 to your computer and use it in GitHub Desktop.
Save fcgomes92/62008e5d440ae4117d49e93f477e0102 to your computer and use it in GitHub Desktop.
iSort changed files using git diff
import os
import sys
from subprocess import call, check_output
from isort import SortImports
def isort_all():
path = sys.argv[1]
abs_path = os.path.abspath(path)
os.chdir(abs_path)
file_list = check_output(['git', 'diff', '--name-only'])
if type(file_list) is bytes:
file_list = file_list.decode().strip().split('\n')
for file_name in file_list:
if file_name != '':
print("Checking: {}".format(file_name))
SortImports(file_name)
print("="*80)
print("DONE")
else:
return None
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: {} [path]'.format(sys.argv[0]))
else:
isort_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment