[PATCH] formatting_script: Add formatting script

ohilyard at iol.unh.edu ohilyard at iol.unh.edu
Wed Mar 2 19:42:56 CET 2022


From: Owen Hilyard <ohilyard at iol.unh.edu>

Added a formatting script to run black an isort with. By default, it
will run in the current working directory. If $1 is specified and not
either "-h" or "--help", it will run in that directory instead. This
does not allow checking for a git diff after formatting (for rejecting
patches in CI), but that should be fairly easy to implement in a wrapper
script.

Signed-off-by: Owen Hilyard <ohilyard at iol.unh.edu>
---
 format.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 format.sh

diff --git a/format.sh b/format.sh
new file mode 100755
index 00000000..d35c0bf1
--- /dev/null
+++ b/format.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+function main() {
+    # The directory to work on is either passed in as argument 1,
+    # or is the current working directory
+    DIRECTORY=${1:-`pwd`}
+    LINE_LENGTH=88
+
+    isort \
+      --overwrite-in-place \
+      --profile black \
+      -j `nproc` \
+      --line-length $LINE_LENGTH \
+      --python-version auto \
+      $DIRECTORY
+
+    black \
+      --line-length $LINE_LENGTH \
+      --required-version 22.1.0 \
+      --target-version py38 \
+      --safe \
+      $DIRECTORY
+}
+
+function help() {
+  echo "usage: format.sh <directory>"
+}
+
+if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+  help
+  exit 0
+fi
+
+main "$1"
+
-- 
2.30.2



More information about the dts mailing list