Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Docathon][CodeStyle] refine ci and pre-commit #6253

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion CONTRIBUTING_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ API 文档是飞桨框架的 API 文档,包含了飞桨框架 API 的说明介

## 提交 PR

你对于飞桨文档的任何修改,都应该通过提交 PR 的方式来完成,具体的方法可以参考[提交 PR](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/08_contribution/local_dev_guide.html)。
你对于飞桨文档的任何修改,都应该通过提交 PR 的方式来完成,具体的方法可以参考[提交 PR](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/08_contribution/local_dev_guide.html)。
2 changes: 1 addition & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

docs 是 [PaddlePaddle 官网文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/index_cn.html) 的源文件。

注意:英文版 API 文档直接从[PaddlePaddle/Paddle](https://github.com/PaddlePaddle/Paddle) 的 docstring 中生成,[飞桨其他项目](https://www.paddlepaddle.org.cn/overview)的文档分别在其对应的位置中管理。
注意:英文版 API 文档直接从[PaddlePaddle/Paddle](https://github.com/PaddlePaddle/Paddle) 的 docstring中生成,[飞桨其他项目](https://www.paddlepaddle.org.cn/overview)的文档分别在其对应的位置中管理。

## 仓库结构

Expand Down
4 changes: 0 additions & 4 deletions ci_scripts/check_api_cn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ echo $need_check_cn_doc_files
# Check COPY-FROM is parsed into Sample Code
echo "Run COPY-FROM parsed into Sample Code Check"
python check_copy_from_parsed_into_sample_code.py "${OUTPUTDIR}/zh/${VERSIONSTR}/" $need_check_cn_doc_files
if [ $? -ne 0 ];then
echo "ERROR: Exist COPY-FROM has not been parsed into sample code, please check COPY-FROM in the above files"
exit 1
fi
5 changes: 0 additions & 5 deletions ci_scripts/check_api_label_cn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ all_git_files=`git diff --name-only --diff-filter=ACMR upstream/${BRANCH} | sed
echo $all_git_files
echo "Run API_LABEL Checking"
python check_api_label_cn.py ${DOCROOT} ${APIROOT} $all_git_files

if [ $? -ne 0 ];then
echo "ERROR: api_label is not correct, please check api_label in the above files"
exit 1
fi
4 changes: 4 additions & 0 deletions ci_scripts/check_api_parameters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ then
else
python check_api_parameters.py --rst-files "${need_check_files}" --api-info $2
if [ $? -ne 0 ];then
set +x
echo "************************************************************************************"
echo "api parameters check failed."
echo "************************************************************************************"
set -x
exit 5
fi
fi
78 changes: 41 additions & 37 deletions ci_scripts/check_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,50 @@
#=================================================
# Utils
#=================================================
set +x

set -ex
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

if [ -z ${BRANCH} ]; then
BRANCH="develop"
# use pre-commit 2.17
if ! [[ $(pre-commit --version) == *"2.17.0"* ]]; then
pip install pre-commit==2.17.0 1>nul
fi

REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/.." && pwd )"
echo ${REPO_ROOT}

function prepare_env(){
pip install pre-commit pylint # pytest
}

function abort(){
echo "Your change doesn't follow PaddlePaddle's code style." 1>&2
echo "Please use pre-commit to check what is wrong." 1>&2
exit 1
}


function check_style(){
trap 'abort' 0
pre-commit install
commit_files=on
for file_name in `git diff --name-only --diff-filter=ACMR upstream/${BRANCH}`;do
if ! pre-commit run --files ../$file_name ; then
git diff
commit_files=off
echo "Please check the code style of ${file_name}"
fi
done
if [ $commit_files == 'off' ];then
echo "======================================================================="
echo "Code style check failed! Please check the error info above carefully."
echo "======================================================================="
exit 1
diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH})
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 formatted by code format hook. You should use pre-commit to \
format them before git push."
echo -e '************************************************************************************\n'
git diff 2>&1
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 ""
fi
trap 0
}
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
echo -e '************************************************************************************\n'

# prepare_env
check_style
exit ${check_error}
10 changes: 10 additions & 0 deletions ci_scripts/ci_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,23 @@ if [ "${need_check_cn_doc_files}" = "" ] ; then
else
/bin/bash -x ${DIR_PATH}/check_api_cn.sh "${need_check_cn_doc_files}"
if [ $? -ne 0 ];then
set +x
echo "************************************************************************************"
echo "ERROR: Exist COPY-FROM has not been parsed into sample code, please check COPY-FROM in the above files"
Copy link
Member

Choose a reason for hiding this comment

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

这些也用 ************************************************************************************ 包裹吧

这样的子问题用 *,summary 用 =,会统一一些

echo "************************************************************************************"
set -x
EXIT_CODE=1
fi
fi

# 5 Chinese api_label check
/bin/bash -x ${DIR_PATH}/check_api_label_cn.sh
if [ $? -ne 0 ];then
set +x
echo "************************************************************************************"
echo "ERROR: api_label is not correct, please check api_label in the above files"
echo "************************************************************************************"
set -x
EXIT_CODE=1
fi

Expand Down
5 changes: 4 additions & 1 deletion docs/api/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ def parse_module_file(mod):
for node in mod_ast.body:
short_names = []
if (
isinstance(node, (ast.ClassDef, ast.FunctionDef))
(
isinstance(node, ast.ClassDef)
or isinstance(node, ast.FunctionDef)
)
and hasattr(node, 'name')
and hasattr(sys.modules[mod_name], node.name)
and node.name[0] != '_'
Expand Down