From 108fec78d74c91b7271fd791985816a2127032a6 2020-02-07 02:10:25 From: Matthias Bussonnier Date: 2020-02-07 02:10:25 Subject: [PATCH] Add tool to automatically upgrade a file. Push syntax to 36+, apply black; do the commits and add those comits to git-ignore-revs. --- diff --git a/tools/autoformat_file b/tools/autoformat_file new file mode 100755 index 0000000..3b6b71d --- /dev/null +++ b/tools/autoformat_file @@ -0,0 +1,46 @@ +#!/bin/bash + +set -ueo pipefail +FILE=$1 + +echo "will update $FILE" + +echo $LINENO $? +pyupgrade --py36-plus --exit-zero-even-if-changed $FILE + +echo $LINENO $? +git commit -am"Apply pyupgrade to $FILE + + pyupgrade --py36-plus $FILE + +To ignore those changes when using git blame see the content of +.git-blame-ignore-revs" + +HASH=$(git rev-parse HEAD) + +echo "$HASH # apply pyupgrade to $FILE" >> .git-blame-ignore-revs + +git commit -am'Update .git-blame-ignore-revs with previous commit' + +##### + +black --target-version py36 $FILE + + +git commit -am"Apply black to $FILE + + black --target-version py36 $FILE + +To ignore those changes when using git blame see the content of +.git-blame-ignore-revs" + +HASH=$(git rev-parse HEAD) + +echo "$HASH # apply black to $FILE" >> .git-blame-ignore-revs + +git commit -am'Update .git-blame-ignore-revs with previous commit' + +echo +echo "Updating, reformatting and adding to .git-blame-ignore-revs successful" + +