Skip to content

Instantly share code, notes, and snippets.

@JulianWgs
Created May 17, 2021 21:20
Show Gist options
  • Save JulianWgs/ba762ba729d8f17090cafd5230261ab2 to your computer and use it in GitHub Desktop.
Save JulianWgs/ba762ba729d8f17090cafd5230261ab2 to your computer and use it in GitHub Desktop.
Run Python black only for specific git author email address
import git
import black
from blib2to3.pgen2.tokenize import TokenError
new_lines = list()
author_email = "example@example.org"
filename = "setup.py"
for commit, lines in repo.blame('HEAD', filename):
if author_email == commit.author.email:
try:
new_lines.append(
black.format_str(
"\n".join(lines),
mode=black.Mode()
)
)
except:
new_lines.extend(lines)
else:
new_lines.extend(lines)
open(filename, "w").writelines(new_lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment