Extract isort and black

This commit is contained in:
Michael Wolf
2023-09-20 07:15:33 -06:00
parent 1e942180fe
commit b4f69b21cf
2 changed files with 48 additions and 12 deletions

43
isort-and-black.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
set -uo pipefail
IFS=$'\n\t'
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR/_reformat-common.bash"
file="$1"
if [[ x"$WOULD_REFORMAT" = x"would_reformat" ]] ; then
out1=$(pipx run isort $file 2>/dev/null)
c1="$?"
if [[ x"$c1" != x"0" ]] ; then
# would reorder imports
if [[ x"$c1" = x"1" ]] ; then
exit 1
fi
# syntax error; 123 is normalized to 2
if [[ x"$c1" = x"123" ]] ; then
exit 2
fi
# some other problem that we don't know how to handle
exit 255
fi
out2=$(pipx run black --check $file 2>/dev/null)
c2="$?"
exit "$c2"
fi
if [[ x"$WOULD_REFORMAT" = x"do_reformat" ]] ; then
out1=$(pipx run black $1 2>/dev/null && pipx run isort $file 2>/dev/null)
c="$?"
exit "$c"
fi
exit 255