1
0
mirror of synced 2026-01-13 00:04:47 -05:00
Files
airbyte/airbyte-cdk/python/reference_docs/generate_rst_schema.py
Yevhenii 5eb2af6c08 CDK: Autogenerate reference docs (#4759)
* CDK Autogenerated reference docs: base version

* Update docs config.
Add .readthedocs.yaml file.
Update build html files.

* Update .gitignore.
Remove sphinx build files.

* Add newline at the end of .gitignore

* Update setup.py requirements.
Update .readthedocs.yaml config.

* Update rst files.
Add Makefile rst config.

* Update CDK docstring format.
Change rst layout.
Update sphinx config.

* Add Sphinx docs.
Update index.rst.
Update abstract_source.py docstrings.

* Override master_doc and package templates.
Add docs schema enerator script.
Update sphinx docs.

* Add `Publishing to Read the Docs` section to sphinx-docs.md".
Replace sphinx-docs.md to `airbyte-cdk` module.

* Update sphinx-docs.md section name

* Bump airbyte-cdk version.
Update CHANGELOG.md.

Co-authored-by: ykurochkin <y.kurochkin@zazmic.com>
Co-authored-by: Vadym Hevlich <vege1wgw@gmail.com>
2021-10-22 20:47:48 +03:00

47 lines
1.6 KiB
Python
Executable File

#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
import sys
from os import path
from typing import Any, Dict
from sphinx.cmd.quickstart import QuickstartRenderer
from sphinx.ext.apidoc import get_parser, main, recurse_tree, write_file
from sphinx.locale import __
from sphinx.util import ensuredir
def write_master_file(templatedir: str, master_name: str, values: Dict, opts: Any):
template = QuickstartRenderer(templatedir=templatedir)
opts.destdir = opts.destdir[: opts.destdir.rfind("/")]
write_file(master_name, template.render(f"{templatedir}/master_doc.rst_t", values), opts)
if __name__ == "__main__":
parser = get_parser()
parser.add_argument("--master", metavar="MASTER", default="index", help=__("master document name"))
args = parser.parse_args(sys.argv[1:])
rootpath = path.abspath(args.module_path)
# normalize opts
if args.header is None:
args.header = rootpath.split(path.sep)[-1]
if args.suffix.startswith("."):
args.suffix = args.suffix[1:]
if not path.isdir(rootpath):
print(__(f"{rootpath} is not a directory."), file=sys.stderr)
sys.exit(1)
if not args.dryrun:
ensuredir(args.destdir)
excludes = [path.abspath(exclude) for exclude in args.exclude_pattern]
modules = recurse_tree(rootpath, excludes, args, args.templatedir)
template_values = {
"top_modules": [{"path": f"api/{module}", "caption": module.split(".")[1].title()} for module in modules if module.count(".") == 1],
"maxdepth": args.maxdepth,
}
write_master_file(templatedir=args.templatedir, master_name=args.master, values=template_values, opts=args)
main()