From 3f02b19ce0e7b81b9c4f222bf86879d5ff319d0d Mon Sep 17 00:00:00 2001 From: tianshuo78520a <707759223@qq.com> Date: Mon, 5 Jun 2023 11:10:10 +0800 Subject: [PATCH] Monitor print usage and skip code examples (#54210) --- paddle/scripts/paddle_build.sh | 8 ++++---- tools/check_api_approvals.sh | 22 ++++++++++++++++++++++ tools/check_file_diff_approvals.sh | 6 ------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index eec26ca68b5..ac4d3608762 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3124,20 +3124,20 @@ function build_document_preview() { # origin name: example function exec_samplecode_test() { if [ -d "${PADDLE_ROOT}/build/pr_whl" ];then - pip install ${PADDLE_ROOT}/build/pr_whl/*.whl --force-reinstall + pip install ${PADDLE_ROOT}/build/pr_whl/*.whl else echo "WARNING: PR wheel is not found. Use develop wheel !!!" - pip install ${PADDLE_ROOT}/build/python/dist/*.whl --force-reinstall + pip install ${PADDLE_ROOT}/build/python/dist/*.whl fi python -c "import paddle;print(paddle.__version__);paddle.version.show()" cd ${PADDLE_ROOT}/tools if [ "$1" = "cpu" ] ; then - python sampcd_processor.py cpu; example_error=$? + python sampcd_processor.py --debug cpu; example_error=$? elif [ "$1" = "gpu" ] ; then SAMPLE_CODE_EXEC_THREADS=${SAMPLE_CODE_EXEC_THREADS:-2} - python sampcd_processor.py --threads=${SAMPLE_CODE_EXEC_THREADS} gpu; example_error=$? + python sampcd_processor.py --threads=${SAMPLE_CODE_EXEC_THREADS} --debug gpu; example_error=$? fi if [ "$example_error" != "0" ];then echo "Code instance execution failed" >&2 diff --git a/tools/check_api_approvals.sh b/tools/check_api_approvals.sh index 36449fd1444..55c348365e1 100644 --- a/tools/check_api_approvals.sh +++ b/tools/check_api_approvals.sh @@ -116,6 +116,28 @@ if [ "${ADDED_OP_USE_DEFAULT_GRAD_MAKER}" != "" ]; then check_approval 1 6888866 7913861 fi +OUTPUT_LOG=`git diff -U0 upstream/$BRANCH | grep "^+" | grep -Ew "print|printf|fprintf|std::cout" || true` +if [ "$OUTPUT_LOG" != "" ];then + git diff -U0 upstream/$BRANCH |grep "^+" | grep -Ew "print|printf|fprintf|std::cout"|sed 's#[ ][ ]##g'|sed 's#+##g' >/tmp/print.txt + samplecode=`find tools/samplecode_temp -type f || true` + sample_status=0 + if [ "$samplecode" != "" ];then + cat `find tools/samplecode_temp -type f` >/tmp/samplecode.txt + sed -i s#\"#\'#g /tmp/samplecode.txt + while read line + do + code_in=`grep "$line" /tmp/samplecode.txt || true` + if [ "$code_in" == "" ];then + sample_status=1 + fi + done