Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[CodeStyle] add more information when codestyle check failed #47116

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/analysisPyXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import re
import os
import sys
import argparse


def analysisPyXml(rootPath, ut):
Expand Down
2 changes: 1 addition & 1 deletion tools/check_op_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
def diff_vars(origin_vars, new_vars):
global error
var_error = False
var_changed_error_massage = {}
var_changed_error_massage = {}
var_add_massage = []
var_add_dispensable_massage = []
var_deleted_error_massage = []
Expand Down
24 changes: 19 additions & 5 deletions tools/codestyle/pre_commit.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -24,20 +24,21 @@ fi
readonly VERSION="13.0.0"
version=$(clang-format -version)
if ! [[ $(python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1$2}') -ge 36 ]]; then
echo "clang-format installation by pip need python version great equal 3.6,
echo "clang-format installation by pip need python version great equal 3.6,
please change the default python to higher version."
exit 1
fi

diff_files=$(git diff --numstat ${BRANCH} | awk '{print $NF}')
num_diff_files=$(echo "$diff_files" | wc -l)
echo -e "diff files between pr and ${BRANCH}:\n${diff_files}"

echo "Checking code style by pre-commit ..."
pre-commit run --files ${diff_files};check_error=$?

if test ! -z "$(git diff)"; then
echo -e '\n************************************************************************************'
echo -e "These files have been formated by code format hook. You should use pre-commit to \
echo -e "These files have been formatted by code format hook. You should use pre-commit to \
format them before git push."
echo -e '************************************************************************************\n'
git diff 2>&1
Expand All @@ -46,6 +47,19 @@ fi
echo -e '\n***********************************'
if [ ${check_error} != 0 ];then
echo "Your PR code style check failed."
echo "Please install pre-commit locally and set up git hook scripts:"
echo ""
echo " pip install pre-commit==2.17.0"
echo " pre-commit install"
echo ""
if [[ $num_diff_files -le 100 ]];then
echo "Then, run pre-commit to check codestyle issues in your PR:"
echo ""
echo " pre-commit run --files" $(echo ${diff_files[*]} | tr "\n" " ")
echo ""
Copy link
Member Author

@SigureMo SigureMo Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仅仅提示安装命令只能保证新的 commit 可以通过,而不能保证 PR 里之前的 commit 通过,因此这里命令用于提示如何复现这个 PR 里的全部问题

image

这里提示的命令与 37 行一致,以保证本地可以复现/自动修复 CI 上的相关问题

为避免一些较大的 PR(如一些全量替换)时这里命令长度过长导致难以注意到有效的信息,仅仅会在修改文件数量小于等于 100 时提示本信息

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其余两个文件目前只是用于触发 pre-commit 测试效果,如果没有问题就可以直接恢复了

fi
echo "For more information, please refer to our codestyle check guide:"
echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html"
else
echo "Your PR code style check passed."
fi
Expand Down