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:
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
#
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
#
".*\.(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
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:
process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" dos_to_unix
+process "tests include source examples contrib" ".*\.py" dos_to_unix
+
#
# Removing trailing whitespace
#
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
#
".*\.(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
}
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.
#