From f56290a6b2058cce4b7a91f72aa53576bbaf914b Mon Sep 17 00:00:00 2001 From: zhiboniu Date: Tue, 29 Jun 2021 02:44:38 +0000 Subject: [PATCH] print_signatures: set callable checkrule along --- tools/print_signatures.py | 85 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/tools/print_signatures.py b/tools/print_signatures.py index d4745b39711..65e7c7e0efc 100644 --- a/tools/print_signatures.py +++ b/tools/print_signatures.py @@ -103,13 +103,10 @@ def visit_all_module(mod): if inspect.ismodule(instance): visit_all_module(instance) else: - doc_md5 = md5(instance.__doc__) instance_id = id(instance) if instance_id in IdSet: continue IdSet.add(instance_id) - member_dict[cur_name] = "({}, ('document', '{}'))".format( - cur_name, doc_md5) if hasattr(instance, '__name__') and member_name != instance.__name__: print( @@ -219,7 +216,83 @@ def process_module(m, attr="__all__"): return api_counter -def get_all_api_from_modulelist(): +def check_public_api(): + import paddle + modulelist = [ #npqa + paddle, + paddle.amp, + paddle.nn, + paddle.nn.functional, + paddle.nn.initializer, + paddle.nn.utils, + paddle.static, + paddle.static.nn, + paddle.io, + paddle.jit, + paddle.metric, + paddle.distribution, + paddle.optimizer, + paddle.optimizer.lr, + paddle.regularizer, + paddle.text, + paddle.utils, + paddle.utils.download, + paddle.utils.profiler, + paddle.utils.cpp_extension, + paddle.sysconfig, + paddle.vision, + paddle.vision.datasets, + paddle.vision.models, + paddle.vision.transforms, + paddle.vision.ops, + paddle.distributed, + paddle.distributed.fleet, + paddle.distributed.fleet.utils, + paddle.distributed.parallel, + paddle.distributed.utils, + paddle.callbacks, + paddle.hub, + paddle.autograd, + paddle.incubate, + paddle.inference, + paddle.onnx, + paddle.device + ] + + apinum = 0 + alldict = {} + for module in modulelist: + if hasattr(module, '__all__'): + old_all = module.__all__ + else: + old_all = [] + dirall = dir(module) + for item in dirall: + if item.startswith('__'): + continue + old_all.append(item) + apinum += len(old_all) + alldict.update({module.__name__: old_all}) + + old_all = [] + dirall = dir(paddle.Tensor) + for item in dirall: + if item.startswith('_'): + continue + old_all.append(item) + apinum += len(old_all) + alldict.update({'paddle.Tensor': old_all}) + + for module, allapi in alldict.items(): + for member_name in allapi: + cur_name = module + '.' + member_name + instance = eval(cur_name) + doc_md5 = md5(instance.__doc__) + member_dict[cur_name] = "({}, ('document', '{}'))".format(cur_name, + doc_md5) + + +def check_allmodule_callable(): import paddle modulelist = [paddle] for m in modulelist: @@ -255,9 +328,9 @@ def parse_args(): if __name__ == '__main__': args = parse_args() - + check_allmodule_callable() if args.method == 'from_modulelist': - get_all_api_from_modulelist() + check_public_api() for name in member_dict: print(name, member_dict[name]) elif args.method == 'get_all_api': -- GitLab