Skip to content

Instantly share code, notes, and snippets.

@deniskrumko
Created February 25, 2019 08:35
Show Gist options
  • Save deniskrumko/bca43865ea92af5add7ab954380eca84 to your computer and use it in GitHub Desktop.
Save deniskrumko/bca43865ea92af5add7ab954380eca84 to your computer and use it in GitHub Desktop.
Run isort only for modified files
import subprocess
result = subprocess.check_output(['git', 'status', '-s'])
result = result.decode('utf-8')
files = []
for line in result.split('\n'):
line = line.strip()
if line.startswith('M') or line.startswith('??') or line.startswith('A'):
path = line.split()[1]
files.append(path)
print(f'Found changed file: {path}')
if not files:
exit('Files not found!')
print('\nRunning isort\n')
for f in files:
command = f'isort {f} -y -rc'
subprocess.run(command.split())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment