From 3c98fdd93e7937242a12efe1d44c342c17b3dab5 Mon Sep 17 00:00:00 2001 From: Chen Long Date: Fri, 14 Aug 2020 10:27:27 +0800 Subject: [PATCH] test add api (#2381) * test add api * add_api test=develop --- doc/fluid/api/index_en.rst | 1 + doc/fluid/api/review_tmp.rst | 9 +++ .../api/review_tmp/MarginRankingLoss.rst | 9 +++ .../api/review_tmp/margin_ranking_loss.rst | 7 ++ gen_index.py | 72 +++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 doc/fluid/api/review_tmp.rst create mode 100644 doc/fluid/api/review_tmp/MarginRankingLoss.rst create mode 100644 doc/fluid/api/review_tmp/margin_ranking_loss.rst create mode 100644 gen_index.py diff --git a/doc/fluid/api/index_en.rst b/doc/fluid/api/index_en.rst index 3d98746f0..f36071538 100644 --- a/doc/fluid/api/index_en.rst +++ b/doc/fluid/api/index_en.rst @@ -32,3 +32,4 @@ API Reference regularizer.rst transpiler.rst unique_name.rst + review_tmp.rst diff --git a/doc/fluid/api/review_tmp.rst b/doc/fluid/api/review_tmp.rst new file mode 100644 index 000000000..e39366bce --- /dev/null +++ b/doc/fluid/api/review_tmp.rst @@ -0,0 +1,9 @@ +================= +paddle.review_tmp +================= + +.. toctree:: + :maxdepth: 1 + + review_tmp/MarginRankingLoss.rst + review_tmp/margin_ranking_loss.rst diff --git a/doc/fluid/api/review_tmp/MarginRankingLoss.rst b/doc/fluid/api/review_tmp/MarginRankingLoss.rst new file mode 100644 index 000000000..edc5d1cc5 --- /dev/null +++ b/doc/fluid/api/review_tmp/MarginRankingLoss.rst @@ -0,0 +1,9 @@ +.. _api_nn_loss_MarginRankingLoss_tmp: + +MarginRankingLoss +----------------- + +.. autoclass:: paddle.nn.loss.MarginRankingLoss + :members: + :inherited-members: + :noindex: diff --git a/doc/fluid/api/review_tmp/margin_ranking_loss.rst b/doc/fluid/api/review_tmp/margin_ranking_loss.rst new file mode 100644 index 000000000..289d1928b --- /dev/null +++ b/doc/fluid/api/review_tmp/margin_ranking_loss.rst @@ -0,0 +1,7 @@ +.. _api_nn_functional_margin_ranking_loss_tmp: + +margin_ranking_loss +------------------- + +.. autofunction:: paddle.nn.functional.margin_ranking_loss + :noindex: diff --git a/gen_index.py b/gen_index.py new file mode 100644 index 000000000..e2817e3ab --- /dev/null +++ b/gen_index.py @@ -0,0 +1,72 @@ +import argparse +import sys +import types +import os +import contextlib + + +def parse_arg(): + parser = argparse.ArgumentParser() + parser.add_argument( + '--api_path', + type=str, + default='paddle.nn.functional.l1_loss', + help='the function/class path') + parser.add_argument( + '--is_class', + type=str, + default='False', + help='whether function or class, False means function') + return parser.parse_args() + + +def add_index(en_doc_review_dir, api_name): + + stream = open(en_doc_review_dir + '.rst', 'a') + stream.write(' review_tmp/' + api_name + '.rst\n') + stream.close() + print('add index to ' + en_doc_review_dir + '.rst success') + + +def add_file(en_doc_review_dir, api_path, is_class=False): + + api_path_list = api_path.split('.') + api_name = api_path_list[-1] + api_title = '_'.join(api_path_list[1:]) + + stream = open(en_doc_review_dir + '/' + api_name + '.rst', 'w') + stream.write('.. _api_' + api_title + ':\n') + stream.write('\n') + stream.write(api_name + '\n') + for i in range(max(9, len(api_name))): + stream.write('-') + stream.write('\n') + stream.write('\n') + + if is_class == 'True': + stream.write('.. autoclass:: ' + api_path + '\n') + stream.write(' :members:\n') + stream.write(' :inherited-members:\n') + else: + stream.write('.. autofunction:: ' + api_path + '\n') + + stream.write(' :noindex:\n') + stream.close() + print('add' + en_doc_review_dir + '/' + api_name + '.rst success') + + +def main(): + args = parse_arg() + api_path = args.api_path + is_class = args.is_class + api_name = api_path.split('.')[-1] + + fluid_doc_path = os.getcwd() + en_doc_review_dir = fluid_doc_path + '/doc/fluid/api/review_tmp' + + add_index(en_doc_review_dir, api_name) + add_file(en_doc_review_dir, api_path, is_class) + + +if __name__ == '__main__': + main() -- GitLab