forked from airbytehq/airbyte-python-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
85 lines (65 loc) · 2.4 KB
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
"""Generate docs for all public modules in the Airbyte CDK and save them to docs/generated.
Usage:
poetry run python docs/generate.py
Or with Poe-the-Poet:
poe docs-generate
poe docs-preview
"""
from __future__ import annotations
import os
import pathlib
import shutil
from typing import cast
import pdoc
def run() -> None:
"""Generate docs for all public modules in the Airbyte CDK and save them to docs/generated."""
public_modules = [
"airbyte_cdk",
]
# Walk all subdirectories and add them to the `public_modules` list
# if they do not begin with a "_" character.
for parent_dir, dirs, files in os.walk(pathlib.Path("airbyte_cdk")):
for dir_name in dirs:
if "/." in parent_dir or "/_" in parent_dir:
continue
if dir_name.startswith((".", "_")):
continue
print(f"Found module dir: {parent_dir + '|' + dir_name}")
# Check if the directory name does not begin with a "_"
module = (parent_dir + "." + dir_name).replace("/", ".")
if "._" not in module and not module.startswith("_"):
public_modules.append(module)
for file_name in files:
if not file_name.endswith(".py"):
continue
if file_name in ["py.typed"]:
continue
if file_name.startswith((".", "_")):
continue
print(f"Found module file: {'|'.join([parent_dir, file_name])}")
module = (
cast(str, ".".join([parent_dir, file_name])).replace("/", ".").removesuffix(".py")
)
public_modules.append(module)
# recursively delete the docs/generated folder if it exists
if pathlib.Path("docs/generated").exists():
shutil.rmtree("docs/generated")
pdoc.render.configure(
template_directory="docs",
show_source=True,
search=True,
logo="https://docs.airbyte.com/img/logo-dark.png",
favicon="https://docs.airbyte.com/img/favicon.png",
mermaid=True,
docformat="google",
)
nl = "\n"
print(f"Generating docs for public modules: {nl.join(public_modules)}")
pdoc.pdoc(
*set(public_modules),
output_directory=pathlib.Path("docs/generated"),
)
if __name__ == "__main__":
run()