未验证 提交 abfcb126 编写于 作者: T tianshuo78520a 提交者: GitHub

Make the gen_doc script support paddle api version 2.0 (#1944)

* change gen_doc

* change gen_doc
上级 3abbcb00
...@@ -19,6 +19,7 @@ import types ...@@ -19,6 +19,7 @@ import types
import os import os
import contextlib import contextlib
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.tensor as tensor
def parse_arg(): def parse_arg():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
...@@ -29,8 +30,11 @@ def parse_arg(): ...@@ -29,8 +30,11 @@ def parse_arg():
'--module_prefix', type=str, help='Generate the prefix of module') '--module_prefix', type=str, help='Generate the prefix of module')
parser.add_argument( parser.add_argument(
'--output', type=str, help='Output file or output directory for output rst') '--output', type=str, help='Output file or output directory for output rst')
parser.add_argument(
'--output_name', type=str, help='Output file or output directory for output rst')
parser.add_argument( parser.add_argument(
'--to_multiple_files', type=bool, default=False, help='Whether to separate to multiple files') '--to_multiple_files', type=bool, default=False, help='Whether to separate to multiple files')
return parser.parse_args() return parser.parse_args()
def print_item(self, name): def print_item(self, name):
...@@ -140,7 +144,7 @@ class DocGenerator(object): ...@@ -140,7 +144,7 @@ class DocGenerator(object):
self.stream.write(".. _api_{0}_{1}:\n\n".format("_".join( self.stream.write(".. _api_{0}_{1}:\n\n".format("_".join(
self.module_prefix.split(".")), name)) self.module_prefix.split(".")), name))
def generate_doc(module_name, module_prefix, output, to_multiple_files): def generate_doc(module_name, module_prefix, output, output_name, to_multiple_files):
if module_name == "": if module_name == "":
module_name = None module_name = None
...@@ -150,22 +154,22 @@ def generate_doc(module_name, module_prefix, output, to_multiple_files): ...@@ -150,22 +154,22 @@ def generate_doc(module_name, module_prefix, output, to_multiple_files):
gen = DocGenerator() gen = DocGenerator()
if module_name is None: if module_name is None:
gen.module = fluid gen.module = eval(output_name)
gen.module_name = 'fluid' gen.module_name = str(output_name)
else: else:
gen.module = fluid gen.module = eval(output_name)
for each_module_name in module_name.split('.'): for each_module_name in module_name.split('.'):
if not hasattr(gen.module, each_module_name): if not hasattr(gen.module, each_module_name):
raise ValueError("Cannot find fluid.{0}".format(module_name)) raise ValueError("Cannot find fluid.{0}".format(module_name))
else: else:
gen.module = getattr(gen.module, each_module_name) gen.module = getattr(gen.module, each_module_name)
gen.module_name = "fluid." + module_name gen.module_name = output_name + "." + module_name
if module_prefix is None: if module_prefix is None:
gen.module_prefix = gen.module_name gen.module_prefix = gen.module_name
else: else:
gen.module_prefix = "fluid." + module_prefix gen.module_prefix = output_name + "." + module_prefix
dirname = output if to_multiple_files else os.path.dirname(output) dirname = output if to_multiple_files else os.path.dirname(output)
if len(dirname) > 0 and (not os.path.exists(dirname) or not os.path.isdir(dirname)): if len(dirname) > 0 and (not os.path.exists(dirname) or not os.path.isdir(dirname)):
...@@ -199,7 +203,7 @@ def generate_doc(module_name, module_prefix, output, to_multiple_files): ...@@ -199,7 +203,7 @@ def generate_doc(module_name, module_prefix, output, to_multiple_files):
def main(): def main():
args = parse_arg() args = parse_arg()
generate_doc(args.module_name, args.module_prefix, args.output, args.to_multiple_files) generate_doc(args.module_name, args.module_prefix, args.output, args.output_name, args.to_multiple_files)
if __name__ == '__main__': if __name__ == '__main__':
......
#!/bin/bash #!/bin/bash
#for module in nn
#do
# python gen_doc.py --module_name layers.${module} --module_prefix layers --output layers/${module} --to_multiple_files True
#done
#for module in control_flow nn io ops tensor learning_rate_scheduler detection metric_op
#do
# python gen_doc.py --module_name layers.${module} --module_prefix layers --output layers/${module}.rst
#done
for module in layers dataset clip metrics executor initializer io nets optimizer profiler regularizer transpiler backward profiler unique_name dygraph for module in layers dataset clip metrics executor initializer io nets optimizer profiler regularizer transpiler backward profiler unique_name dygraph
do do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --to_multiple_files True python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name fluid --to_multiple_files True
python gen_module_index.py ${module} fluid.${module} python gen_module_index.py ${module} fluid.${module}
done done
python gen_doc.py --module_name "" --module_prefix "" --output fluid --to_multiple_files True python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_name fluid --to_multiple_files True
python gen_module_index.py fluid fluid python gen_module_index.py fluid fluid
python gen_index.py python gen_index.py
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册