未验证 提交 ba7e2a9f 编写于 作者: R Ren Wei (任卫) 提交者: GitHub

remove the tricks for `paddle.fluid.layers.ops.func` (#33731)

* refactor check_pr_approval, allow using github login-id

2. remove the tricks for paddle.fluid.layers.ops.func

* add testcases

* simplify the test data, and added to file diff approvals

* remove a approver

* test_print_signatrues runs on a simple pipeline, no paddle installed

* testcases for print_signatrures and sampcd . python3 only.

* remove unused import directives

* remove unused import directives
上级 dfbfbd01
...@@ -38,11 +38,7 @@ function add_failed(){ ...@@ -38,11 +38,7 @@ function add_failed(){
api_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.api ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.api` api_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.api ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.api`
ops_func_in_diff=$(echo ${api_spec_diff} | grep '\bpaddle\.fluid\.layers\.ops\.func\b') if [ "$api_spec_diff" != "" ]; then
linenum=$(echo ${api_spec_diff} | wc -l | sed 's/[[:space:]]//g')
if [ "${linenum}" = "3" -a "${ops_func_in_diff}" != "" ] ; then
echo "skip paddle.fluid.layers.ops.func"
elif [ "$api_spec_diff" != "" ]; then
echo_line="You must have one RD (XiaoguangHu01 or lanxianghit) approval for API change.\n" echo_line="You must have one RD (XiaoguangHu01 or lanxianghit) approval for API change.\n"
echo_line="${echo_line} and one TPM approval for API change: \n" echo_line="${echo_line} and one TPM approval for API change: \n"
echo_line="${echo_line} jzhang533/ZhangJun, dingjiaweiww/DingJiaWei, Heeenrrry/LiKunLun, TCChenlong/ChenLong for general APIs\n" echo_line="${echo_line} jzhang533/ZhangJun, dingjiaweiww/DingJiaWei, Heeenrrry/LiKunLun, TCChenlong/ChenLong for general APIs\n"
...@@ -54,10 +50,7 @@ elif [ "$api_spec_diff" != "" ]; then ...@@ -54,10 +50,7 @@ elif [ "$api_spec_diff" != "" ]; then
fi fi
api_doc_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.doc ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.doc` api_doc_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.doc ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.doc`
linenum=$(echo ${api_doc_spec_diff} | wc -l | sed 's/[[:space:]]//g') if [ "$api_doc_spec_diff" != "" ]; then
if [ "${linenum}" = "3" -a "${ops_func_in_diff}" != "" ] ; then
echo "skip paddle.fluid.layers.ops.func for doc diff"
elif [ "$api_doc_spec_diff" != "" ]; then
echo_line="You must have one TPM approval for API documents change: \n" echo_line="You must have one TPM approval for API documents change: \n"
echo_line="${echo_line} jzhang533/ZhangJun, dingjiaweiww/DingJiaWei, Heeenrrry/LiKunLun, TCChenlong/ChenLong for general API docs\n" echo_line="${echo_line} jzhang533/ZhangJun, dingjiaweiww/DingJiaWei, Heeenrrry/LiKunLun, TCChenlong/ChenLong for general API docs\n"
echo_line="${echo_line} PangHua/XiangHui for distributed related API docs\n" echo_line="${echo_line} PangHua/XiangHui for distributed related API docs\n"
...@@ -76,8 +69,8 @@ fi ...@@ -76,8 +69,8 @@ fi
op_type_spec_diff=`python ${PADDLE_ROOT}/tools/check_op_register_type.py ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_DEV.spec ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_PR.spec` op_type_spec_diff=`python ${PADDLE_ROOT}/tools/check_op_register_type.py ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_DEV.spec ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_PR.spec`
if [ "$op_type_spec_diff" != "" ]; then if [ "$op_type_spec_diff" != "" ]; then
echo_line="You must have one RD (Aurelius84 (Recommend) or liym27 or zhhsplendid)approval for the data_type registration of new operator. More data_type of new operator should be registered in your PR. Please make sure that both float/double (or int/int64_t) have been registered.\n For more details, please click [https://github.com/PaddlePaddle/Paddle/wiki/Data-types-of-generic-Op-must-be-fully-registered].\n" echo_line="You must have one RD (Aurelius84 (Recommend) or zhhsplendid)approval for the data_type registration of new operator. More data_type of new operator should be registered in your PR. Please make sure that both float/double (or int/int64_t) have been registered.\n For more details, please click [https://github.com/PaddlePaddle/Paddle/wiki/Data-types-of-generic-Op-must-be-fully-registered].\n"
check_approval 1 9j301846 33742067 7913861 check_approval 1 9301846 7913861
fi fi
op_desc_diff=`python ${PADDLE_ROOT}/tools/check_op_desc.py ${PADDLE_ROOT}/paddle/fluid/OP_DESC_DEV.spec ${PADDLE_ROOT}/paddle/fluid/OP_DESC_PR.spec` op_desc_diff=`python ${PADDLE_ROOT}/tools/check_op_desc.py ${PADDLE_ROOT}/paddle/fluid/OP_DESC_DEV.spec ${PADDLE_ROOT}/paddle/fluid/OP_DESC_PR.spec`
...@@ -100,12 +93,9 @@ if [ -n "${echo_list}" ];then ...@@ -100,12 +93,9 @@ if [ -n "${echo_list}" ];then
echo "There are ${failed_num} approved errors." echo "There are ${failed_num} approved errors."
echo "****************" echo "****************"
# L40 L48 L62 has fetch the result out. # L40 L48 L62 has fetch the result out, but there are splitted.
if [ "${api_spec_diff}" != "" ] ; then if [ "${api_spec_diff}" != "" -o "${api_doc_spec_diff}" != "" ] ; then
echo "api_spec_diff: ${api_spec_diff}" python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec ${PADDLE_ROOT}/paddle/fluid/API_PR.spec
fi
if [ "${api_doc_spec_diff}" != "" ] ; then
echo "api_doc_spec_diff: ${api_doc_spec_diff}"
fi fi
if [ "${op_type_spec_diff}" != "" ] ; then if [ "${op_type_spec_diff}" != "" ] ; then
echo "op_type_spec_diff: ${op_type_spec_diff}" echo "op_type_spec_diff: ${op_type_spec_diff}"
......
...@@ -54,6 +54,7 @@ API_FILES=("CMakeLists.txt" ...@@ -54,6 +54,7 @@ API_FILES=("CMakeLists.txt"
"python/paddle/fluid/tests/unittests/white_list/no_grad_set_white_list.py" "python/paddle/fluid/tests/unittests/white_list/no_grad_set_white_list.py"
"tools/print_signatures.py" "tools/print_signatures.py"
"tools/sampcd_processor.py" "tools/sampcd_processor.py"
"tools/check_pr_approval.py"
"paddle/scripts/paddle_build.bat" "paddle/scripts/paddle_build.bat"
"tools/windows/run_unittests.sh" "tools/windows/run_unittests.sh"
"tools/parallel_UT_rule.py" "tools/parallel_UT_rule.py"
...@@ -146,6 +147,9 @@ for API_FILE in ${API_FILES[*]}; do ...@@ -146,6 +147,9 @@ for API_FILE in ${API_FILES[*]}; do
elif [ "${API_FILE}" == "tools/print_signatures.py" ];then elif [ "${API_FILE}" == "tools/print_signatures.py" ];then
echo_line="test_print_signatures.py will be executed for changed print_signatures.py.\n" echo_line="test_print_signatures.py will be executed for changed print_signatures.py.\n"
run_tools_test test_print_signatures.py run_tools_test test_print_signatures.py
elif [ "${API_FILE}" == "tools/checkout_pr_approval.py" ];then
echo_line="test_checkout_pr_approval.py will be executed for changed checkout_pr_approval.py.\n"
run_tools_test test_checkout_pr_approval.py
elif [ "${API_FILE}" == "python/paddle/distributed/fleet/__init__.py" ]; then elif [ "${API_FILE}" == "python/paddle/distributed/fleet/__init__.py" ]; then
echo_line="You must have (fuyinno4 (Recommend), raindrops2sea) approval for ${API_FILE} changes" echo_line="You must have (fuyinno4 (Recommend), raindrops2sea) approval for ${API_FILE} changes"
check_approval 1 35824027 38231817 check_approval 1 35824027 38231817
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import sys import sys
import json import json
...@@ -24,17 +23,24 @@ def check_approval(count, required_reviewers): ...@@ -24,17 +23,24 @@ def check_approval(count, required_reviewers):
json_resp = json.loads(json_buff) json_resp = json.loads(json_buff)
approves = 0 approves = 0
approved_user_ids = [] approved_user_ids = []
approved_user_logins = set()
for review in json_resp: for review in json_resp:
if review["state"] == "APPROVED": if review["state"] == "APPROVED":
approves += 1 approves += 1
approved_user_ids.append(review["user"]["id"]) approved_user_ids.append(review["user"]["id"])
approved_user_logins.add(review["user"]["login"])
# convert to int # convert to int
required_reviewers_int = set() required_reviewers_int = set()
required_reviewers_login = set()
for rr in required_reviewers: for rr in required_reviewers:
required_reviewers_int.add(int(rr)) if rr.isdigit():
required_reviewers_int.add(int(rr))
else:
required_reviewers_login.add(rr)
if len(set(approved_user_ids) & required_reviewers_int) >= count: if len(set(approved_user_ids) & required_reviewers_int) + len(
approved_user_logins & required_reviewers_login) >= count:
print("TRUE") print("TRUE")
else: else:
print("FALSE") print("FALSE")
......
...@@ -17,20 +17,14 @@ Print all signature of a python module in alphabet order. ...@@ -17,20 +17,14 @@ Print all signature of a python module in alphabet order.
Usage: Usage:
./print_signature "paddle.fluid" > signature.txt ./print_signature "paddle.fluid" > signature.txt
""" """
from __future__ import print_function
import importlib
import inspect import inspect
import collections import collections
import sys import sys
import pydoc
import hashlib import hashlib
import platform
import functools
import pkgutil import pkgutil
import logging import logging
import argparse import argparse
import paddle
member_dict = collections.OrderedDict() member_dict = collections.OrderedDict()
...@@ -80,11 +74,7 @@ def is_primitive(instance): ...@@ -80,11 +74,7 @@ def is_primitive(instance):
ErrorSet = set() ErrorSet = set()
IdSet = set() IdSet = set()
skiplist = [ skiplist = []
'paddle.vision.datasets.DatasetFolderImageFolder',
'paddle.truncdigamma',
'paddle.fluid.layers.ops.func',
]
def visit_all_module(mod): def visit_all_module(mod):
...@@ -140,6 +130,7 @@ def get_all_api(root_path='paddle', attr="__all__"): ...@@ -140,6 +130,7 @@ def get_all_api(root_path='paddle', attr="__all__"):
""" """
walk through the paddle package to collect all the apis. walk through the paddle package to collect all the apis.
""" """
import paddle
global api_info_dict global api_info_dict
api_counter = 0 api_counter = 0
for filefinder, name, ispkg in pkgutil.walk_packages( for filefinder, name, ispkg in pkgutil.walk_packages(
...@@ -229,6 +220,7 @@ def process_module(m, attr="__all__"): ...@@ -229,6 +220,7 @@ def process_module(m, attr="__all__"):
def get_all_api_from_modulelist(): def get_all_api_from_modulelist():
import paddle
modulelist = [paddle] modulelist = [paddle]
for m in modulelist: for m in modulelist:
visit_all_module(m) visit_all_module(m)
......
...@@ -27,7 +27,6 @@ import subprocess ...@@ -27,7 +27,6 @@ import subprocess
import multiprocessing import multiprocessing
import platform import platform
import inspect import inspect
import json
import argparse import argparse
import shutil import shutil
import re import re
......
#! /usr/bin/env python
# Copyright (c) 2021 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.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
TestCases for check_pr_approval.py
"""
import unittest
import subprocess
import sys
class Test_check_approval(unittest.TestCase):
def setUp(self):
self.codeset = 'UTF-8'
# only key info in it
self.jsonstr = """
[
{
"id": 688077074,
"node_id": "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3Njg4MDc3MDc0",
"user": {
"login": "wadefelix",
"id": 1306724,
"type": "User",
"site_admin": false
},
"body": "",
"state": "COMMENTED",
"author_association": "CONTRIBUTOR"
},
{
"id": 688092580,
"node_id": "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3Njg4MDkyNTgw",
"user": {
"login": "MingMingShangTian",
"id": 13469016,
"type": "User",
"site_admin": false
},
"body": "LGTM",
"state": "APPROVED",
"author_association": "CONTRIBUTOR"
},
{
"id": 689175539,
"node_id": "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3Njg5MTc1NTM5",
"user": {
"login": "pangyoki",
"id": 26408901,
"type": "User",
"site_admin": false
},
"body": "LGTM",
"state": "APPROVED",
"author_association": "CONTRIBUTOR"
}
]
""".encode(self.codeset)
def test_ids(self):
cmd = [sys.executable, 'check_pr_approval.py', '1', '26408901']
subprc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error = subprc.communicate(input=self.jsonstr)
self.assertEqual('TRUE', output.decode(self.codeset).rstrip())
def test_logins(self):
cmd = [sys.executable, 'check_pr_approval.py', '1', 'pangyoki']
subprc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error = subprc.communicate(input=self.jsonstr)
self.assertEqual('TRUE', output.decode(self.codeset).rstrip())
def test_ids_and_logins(self):
cmd = [
sys.executable, 'check_pr_approval.py', '2', 'pangyoki', '13469016'
]
subprc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error = subprc.communicate(input=self.jsonstr)
#self.assertEqual('', error.rstrip())
self.assertEqual('TRUE', output.decode(self.codeset).rstrip())
def test_check_with_required_reviewer_not_approved(self):
cmd = [
sys.executable, 'check_pr_approval.py', '2', 'wadefelix',
' 13469016'
]
subprc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error = subprc.communicate(input=self.jsonstr)
self.assertEqual('FALSE', output.decode(self.codeset).rstrip())
if __name__ == '__main__':
unittest.main()
...@@ -23,13 +23,9 @@ sample lines from API_DEV.spec: ...@@ -23,13 +23,9 @@ sample lines from API_DEV.spec:
""" """
import unittest import unittest
import hashlib import hashlib
import inspect
import functools import functools
from print_signatures import md5 from print_signatures import md5
from print_signatures import get_functools_partial_spec from print_signatures import is_primitive
from print_signatures import format_spec
from print_signatures import queue_dict
from print_signatures import member_dict
def func_example(param_a, param_b): def func_example(param_a, param_b):
...@@ -65,30 +61,27 @@ class Test_all_in_print_signatures(unittest.TestCase): ...@@ -65,30 +61,27 @@ class Test_all_in_print_signatures(unittest.TestCase):
digest = algo.hexdigest() digest = algo.hexdigest()
self.assertEqual(digest, md5(func_example.__doc__)) self.assertEqual(digest, md5(func_example.__doc__))
def test_get_functools_partial_spec(self):
partailed_func = functools.partial(func_example, 1)
# args = inspect.getargspec(partailed_func)
self.assertEqual('func_example(args=(1,), keywords={})',
get_functools_partial_spec(partailed_func))
class Test_is_primitive(unittest.TestCase):
class Test_format_spec(unittest.TestCase): def test_single(self):
def test_normal_func_spec(self): self.assertTrue(is_primitive(2))
args = inspect.getargspec(func_example) self.assertTrue(is_primitive(2.1))
self.assertEqual( self.assertTrue(is_primitive("2.1.1"))
'''ArgSpec(args=['param_a', 'param_b'], varargs=None, keywords=None, defaults=None)''', self.assertFalse(
format_spec(args)) is_primitive("hello paddle".encode('UTF-8'))) # True for python2
self.assertFalse(is_primitive(1j))
def test_func_spec_with_partialedfunc_as_param_default(self): self.assertTrue(is_primitive(True))
# but there is no function belongs to this type in API_DEV.spec
args = inspect.getargspec(func_example_2) def test_collection(self):
self.assertEqual( self.assertTrue(is_primitive([]))
'''ArgSpec(args=['func'], varargs=None, keywords=None, defaults=('func_example(args=(1,), keywords={})',))''', self.assertTrue(is_primitive(tuple()))
format_spec(args)) self.assertTrue(is_primitive(set()))
self.assertTrue(is_primitive([1, 2]))
self.assertTrue(is_primitive((1.1, 2.2)))
class Test_queue_dict(unittest.TestCase): self.assertTrue(is_primitive(set([1, 2.3])))
pass self.assertFalse(is_primitive(range(3))) # True for python2
self.assertFalse(is_primitive({}))
self.assertFalse(is_primitive([1, 1j]))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -16,10 +16,7 @@ ...@@ -16,10 +16,7 @@
import unittest import unittest
import os import os
import tempfile
import shutil import shutil
import sys
import importlib
import re import re
import sampcd_processor import sampcd_processor
from sampcd_processor import find_all from sampcd_processor import find_all
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册