gen_params_doc.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. """Generate parms pages."""
  2. import os
  3. import mkdocs_gen_files
  4. repo_base = os.path.abspath(
  5. os.path.join(
  6. os.path.abspath(__file__), os.path.pardir, os.path.pardir, os.path.pardir
  7. )
  8. )
  9. params_source = os.path.join(repo_base, "python", "federatedml", "param")
  10. params_doc_target = os.path.join(repo_base, "doc", "federatedml_component", "params")
  11. md_template = """\
  12. # {name}
  13. ::: federatedml.param.{name}
  14. options:
  15. heading_level: 2
  16. show_source: true
  17. show_root_heading: true
  18. show_root_toc_entry: false
  19. show_root_full_path: false
  20. """
  21. def create_params_doc():
  22. os.makedirs(params_doc_target, exist_ok=True)
  23. for file_name in os.listdir(params_source):
  24. if file_name.endswith(".py") and file_name != "__init__.py":
  25. name = file_name[:-3]
  26. full_doc_path = os.path.join(params_doc_target, f"{name}.md")
  27. with mkdocs_gen_files.open(full_doc_path, "w") as fd:
  28. print(md_template.format(name=name), file=fd)
  29. mkdocs_gen_files.set_edit_path(full_doc_path, os.path.join(params_source, file_name))