未验证 提交 7272526b 编写于 作者: W wanghuancoder 提交者: GitHub

fix count_api_without_core_ops (#35170)

* fix count_api_without_core_ops, test=develop

* fix count_api_without_core_ops, test=develop

* refine, test=develop

* remove test code, test=develop

* remove test, test=develop

* modify check_api_approvals.sh, test=develop
上级 2006fbc4
...@@ -63,7 +63,7 @@ fi ...@@ -63,7 +63,7 @@ fi
api_src_spec_diff=`python ${PADDLE_ROOT}/tools/check_api_source_without_core_ops.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.source.md5 ${PADDLE_ROOT}/paddle/fluid/API_PR.source.md5` api_src_spec_diff=`python ${PADDLE_ROOT}/tools/check_api_source_without_core_ops.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.source.md5 ${PADDLE_ROOT}/paddle/fluid/API_PR.source.md5`
if [ "$api_src_spec_diff" != "" ]; then if [ "$api_src_spec_diff" != "" ]; then
echo_line="APIs without core.ops: \n${api_src_spec_diff}\n" echo_line="APIs without core.ops: \n${api_src_spec_diff}\n"
echo_line="${echo_line}You must have one RD (zhiqiu (Recommend) or phlrain) approval for the api change for the opreator-related api without 'core.ops'.\n" echo_line="${echo_line}You must have one RD (zhiqiu (Recommend) or phlrain) approval for the api change for the opreator-related api without '_C_ops'.\n"
echo_line="${echo_line}For more details, please click [https://github.com/PaddlePaddle/Paddle/wiki/paddle_api_development_manual.md]\n" echo_line="${echo_line}For more details, please click [https://github.com/PaddlePaddle/Paddle/wiki/paddle_api_development_manual.md]\n"
check_approval 1 6888866 43953930 check_approval 1 6888866 43953930
fi fi
......
...@@ -51,13 +51,23 @@ def split_with_and_without_core_ops(member, cur_name): ...@@ -51,13 +51,23 @@ def split_with_and_without_core_ops(member, cur_name):
if cur_name in omitted_list: if cur_name in omitted_list:
return return
if member.__doc__.find(':api_attr: Static Graph') != -1:
return
if cur_name.find('ParamBase') != -1 or cur_name.find(
'Parameter') != -1 or cur_name.find(
'Variable') != -1 or cur_name.find(
'control_flow') != -1 or cur_name.find(
'contrib.mixed_precision') != -1:
return
if inspect.isclass(member): if inspect.isclass(member):
pass pass
else: else:
try: try:
source = inspect.getsource(member) source = inspect.getsource(member)
if source.find('append_op') != -1: if source.find('append_op') != -1:
if source.find('core.ops') != -1: if source.find('core.ops') != -1 or source.find('_C_ops') != -1:
api_with_ops.append(cur_name) api_with_ops.append(cur_name)
else: else:
api_without_ops.append(cur_name) api_without_ops.append(cur_name)
...@@ -117,7 +127,13 @@ def is_primitive(instance): ...@@ -117,7 +127,13 @@ def is_primitive(instance):
return False return False
def visit_all_module(mod, visited, func): ErrorSet = set()
IdSet = set()
skiplist = []
visited_modules = set()
def visit_all_module(mod, func):
mod_name = mod.__name__ mod_name = mod.__name__
if mod_name != 'paddle' and not mod_name.startswith('paddle.'): if mod_name != 'paddle' and not mod_name.startswith('paddle.'):
return return
...@@ -125,29 +141,32 @@ def visit_all_module(mod, visited, func): ...@@ -125,29 +141,32 @@ def visit_all_module(mod, visited, func):
if mod_name.startswith('paddle.fluid.core'): if mod_name.startswith('paddle.fluid.core'):
return return
if mod in visited: if mod in visited_modules:
return return
visited_modules.add(mod)
visited.add(mod) member_names = dir(mod)
if hasattr(mod, "__all__"):
for member_name in ( member_names += mod.__all__
name for member_name in member_names:
for name in (mod.__all__ if hasattr(mod, "__all__") else dir(mod)) if member_name.startswith('_'):
if not name.startswith("_")):
instance = getattr(mod, member_name, None)
if instance is None:
continue continue
cur_name = mod_name + '.' + member_name
if is_primitive(instance): if cur_name in skiplist:
continue
if not hasattr(instance, "__name__"):
continue continue
try:
if inspect.ismodule(instance): instance = getattr(mod, member_name)
visit_all_module(instance, visited, func) if inspect.ismodule(instance):
else: visit_all_module(instance, func)
visit_member(mod.__name__, instance, func) else:
instance_id = id(instance)
if instance_id in IdSet:
continue
IdSet.add(instance_id)
visit_member(mod.__name__, instance, func)
except:
if not cur_name in ErrorSet and not cur_name in skiplist:
ErrorSet.add(cur_name)
def get_apis_with_and_without_core_ops(modules): def get_apis_with_and_without_core_ops(modules):
...@@ -156,7 +175,7 @@ def get_apis_with_and_without_core_ops(modules): ...@@ -156,7 +175,7 @@ def get_apis_with_and_without_core_ops(modules):
api_without_ops = [] api_without_ops = []
for m in modules: for m in modules:
visit_all_module( visit_all_module(
importlib.import_module(m), set(), split_with_and_without_core_ops) importlib.import_module(m), split_with_and_without_core_ops)
return api_with_ops, api_without_ops return api_with_ops, api_without_ops
...@@ -164,7 +183,7 @@ def get_api_source_desc(modules): ...@@ -164,7 +183,7 @@ def get_api_source_desc(modules):
global func_dict global func_dict
func_dict = collections.OrderedDict() func_dict = collections.OrderedDict()
for m in modules: for m in modules:
visit_all_module(importlib.import_module(m), set(), get_md5_of_func) visit_all_module(importlib.import_module(m), get_md5_of_func)
return func_dict return func_dict
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册