This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8c4343c28b86966e48f02430f73b488e8d5a635f
Author: zhongzhijie1 <zhongzhij...@xiaomi.com>
AuthorDate: Tue Jun 17 22:56:33 2025 +0800

    tools/checkpatch.sh: add -x option to auto-format Python files.
    
    Currently only .py files are supported. Non-Python files will report 
"format not implemented".
    
    Signed-off-by: zhongzhijie1 <zhongzhij...@xiaomi.com>
---
 tools/checkpatch.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh
index c2453e032c6..84aaa46bff7 100755
--- a/tools/checkpatch.sh
+++ b/tools/checkpatch.sh
@@ -56,6 +56,7 @@ usage() {
   echo "-m Change-Id check in commit message (coupled with -g)"
   echo "-g <commit list>"
   echo "-f <file list>"
+  echo "-x format supported files (only .py, requires: pip install black)"
   echo "-  read standard input mainly used by git pre-commit hook as below:"
   echo "   git diff --cached | ./tools/checkpatch.sh -"
   echo "Where a <commit list> is any syntax supported by git for specifying 
git revision, see GITREVISIONS(7)"
@@ -93,6 +94,24 @@ is_cmake_file() {
   fi
 }
 
+format_file() {
+  if [ ${@##*.} == 'py' ]; then
+    if command -v black >/dev/null; then
+      echo "Auto-formatting Python file with black: $@"
+      setupcfg="${TOOLDIR}/../.github/linters/setup.cfg"
+      isort --settings-path "${setupcfg}" "$@"
+      black $@
+    else
+      echo "$@: error: black not found. Please install with: pip install black"
+      fail=1
+    fi
+  else
+    # TODO: extend for other file types in the future
+    echo "$@: error: format files type not implemented"
+    fail=1
+  fi
+}
+
 check_file() {
   if [ -x $@ ]; then
     case $@ in
@@ -295,6 +314,9 @@ while [ ! -z "$1" ]; do
   -u )
     encoding=1
     ;;
+  -x )
+    check=format_file
+    ;;
   -f )
     check=check_file
     ;;

Reply via email to