]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Auto-indent Python files. 18432/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 7 May 2025 01:51:50 +0000 (19:51 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 7 May 2025 02:13:10 +0000 (20:13 -0600)
contrib/utilities/indent
contrib/utilities/indent-all
contrib/utilities/indent_common.sh

index 80a08e728e4af6cc924052009e274f4afb689e32..35ebbd984ccafa1202b1f00c2afb7a7a29ec55ba 100755 (executable)
@@ -62,6 +62,7 @@ checks
 
 process_changed "tests include source examples cmake/scripts contrib/python-bindings" ".*\.(cc|h)" format_file
 process_changed "source" ".*\.inst.in" format_inst
+process_changed "tests include source examples contrib" ".*\.py" format_python_file
 
 #
 # Fix permissions and convert to unix line ending if necessary:
@@ -77,6 +78,8 @@ process_changed "tests include source examples cmake/scripts contrib/python-bind
 
 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" dos_to_unix
 
+process_changed "tests include source examples contrib" ".*\.py" dos_to_unix
+
 #
 # Removing trailing whitespace
 #
@@ -86,6 +89,8 @@ process_changed "tests include source examples cmake/scripts contrib/python-bind
 
 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" remove_trailing_whitespace
 
+process_changed "tests include source examples contrib" ".*\.py" remove_trailing_whitespace
+
 #
 # Ensure only a single newline at end of files
 #
@@ -94,3 +99,5 @@ process_changed "tests include source examples cmake/scripts contrib/python-bind
   ".*\.(cc|h|html|dox|txt)" ensure_single_trailing_newline
 
 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" ensure_single_trailing_newline
+
+process_changed "tests include source examples contrib" ".*\.py" ensure_single_trailing_newline
index f4eea6916e8a79798b00e1e46adb033e4fabafbf..25fdf574584f6392129c0d3b673c6848525b94dc 100755 (executable)
@@ -66,6 +66,7 @@ checks
 
 process "tests include source examples contrib/python-bindings" ".*\.(cc|h)" format_file
 process "source" ".*\.inst.in" format_inst
+process "tests include source examples contrib" ".*\.py" format_python_file
 
 #
 # Fix permissions and convert to unix line ending if necessary:
@@ -81,6 +82,8 @@ process "tests include source examples cmake/scripts contrib/python-bindings" \
 
 process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" dos_to_unix
 
+process "tests include source examples contrib" ".*\.py" dos_to_unix
+
 #
 # Removing trailing whitespace
 #
@@ -90,6 +93,8 @@ process "tests include source examples cmake/scripts contrib/python-bindings doc
 
 process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" remove_trailing_whitespace
 
+process "tests include source examples contrib" ".*\.py" remove_trailing_whitespace
+
 #
 # Ensure only a single newline at end of files
 #
@@ -98,3 +103,5 @@ process "tests include source examples cmake/scripts contrib/python-bindings doc
   ".*\.(cc|h|html|dox|txt)" ensure_single_trailing_newline
 
 process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" ensure_single_trailing_newline
+
+process "tests include source examples contrib" ".*\.py" ensure_single_trailing_newline
index f4dfd8e01f07d915e6d504f366c5df044a94d805..40004eb06a2bc84dca2f05252f881320c9e4c59d 100755 (executable)
@@ -160,6 +160,38 @@ format_file()
 }
 export -f format_file
 
+
+#
+# Also format Python files, assuming that we have the 'black'
+# autoindenter available. Black is better than clang-format at not
+# changing the time stamp of a file if the file wasn't actually
+# changed. But, for simplicity, just use the same scheme above
+# so we can use the same reporting mechanism.
+#
+# If 'black' isn't available, just don't do anything.
+#
+# (There is one file, contrib/utilities/dotgdbinit.py, that contains
+# some Python code, but starts with some GDB instruction that confuses
+# the indenter. Exclude that file.)
+#
+format_python_file()
+{
+  if which black > /dev/null ; then
+    file="${1}"
+    if test "$file" = "contrib/utilities/dotgdbinit.py" ; then
+      return ;
+    fi
+      
+    tmpfile="$(mktemp "${TMPDIR}/$(basename "$1").tmp.XXXXXXXX")"
+    cp "${file}" "${tmpfile}"
+    black -q "${tmpfile}"
+    fix_or_report "${file}" "${tmpfile}" "file indented incorrectly"
+    rm -f "${tmpfile}"
+  fi
+}
+export -f format_python_file
+
+
 #
 # Remove trailing whitespace.
 #

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.