diff --git a/doc/fluid/api/gen_doc.py b/doc/fluid/api/gen_doc.py index a45f854ef38715f66d019a58edb4e17dcb1a74c5..b2cd5c5c6c4fb4097f4b4c2aafcb061ade169e4c 100644 --- a/doc/fluid/api/gen_doc.py +++ b/doc/fluid/api/gen_doc.py @@ -19,6 +19,7 @@ import types import os import contextlib import paddle.fluid as fluid +import paddle.tensor as tensor def parse_arg(): parser = argparse.ArgumentParser() @@ -29,8 +30,11 @@ def parse_arg(): '--module_prefix', type=str, help='Generate the prefix of module') parser.add_argument( '--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( '--to_multiple_files', type=bool, default=False, help='Whether to separate to multiple files') + return parser.parse_args() def print_item(self, name): @@ -140,7 +144,7 @@ class DocGenerator(object): self.stream.write(".. _api_{0}_{1}:\n\n".format("_".join( 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 == "": module_name = None @@ -150,22 +154,22 @@ def generate_doc(module_name, module_prefix, output, to_multiple_files): gen = DocGenerator() if module_name is None: - gen.module = fluid - gen.module_name = 'fluid' + gen.module = eval(output_name) + gen.module_name = str(output_name) else: - gen.module = fluid + gen.module = eval(output_name) for each_module_name in module_name.split('.'): if not hasattr(gen.module, each_module_name): raise ValueError("Cannot find fluid.{0}".format(module_name)) else: 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: gen.module_prefix = gen.module_name 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) 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): def main(): 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__': diff --git a/doc/fluid/api/gen_doc.sh b/doc/fluid/api/gen_doc.sh index 1e833161ef0e225e4725136ad3d466d945b69bec..66d014399f99e205f3b3d35642de4db3cddf9108 100644 --- a/doc/fluid/api/gen_doc.sh +++ b/doc/fluid/api/gen_doc.sh @@ -1,22 +1,12 @@ #!/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 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} 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_index.py