Skip to content

Commit

Permalink
Merge pull request #330 from Mara3l/master
Browse files Browse the repository at this point in the history
TRIVIAL: generate.sh - adding master compatibility

Reviewed-by: Jan Kadlec
             https://github.com/hkad98
  • Loading branch information
gdgate authored Aug 23, 2023
2 parents 1c1ae03 + 215c71a commit 8f4514d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 10 additions & 3 deletions scripts/docs/python_ref_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TemplateReplacementSpec:
parent: None | str = None
name: None | str = None
link: None | str = None
path: None | str = None

def render_template_to_str(self, template: str) -> str:
"""
Expand All @@ -32,6 +33,7 @@ def render_template_to_str(self, template: str) -> str:
("PARENT", self.parent),
("NAME", self.name),
("LINK", self.link),
("PATH", self.path),
]:
if replacement is not None:
template = template.replace(token, replacement)
Expand Down Expand Up @@ -94,7 +96,7 @@ def _recursive_create(data_root: dict, dir_root: Path, url_root: str, module_imp

# Create files based on the kind of the data: module/class/function
if kind == "module":
template_spec = TemplateReplacementSpec(name=name, link=name)
template_spec = TemplateReplacementSpec(name=name, link=name, path=obj_module_import_path)
(dir_root / name).mkdir(exist_ok=True)
with (dir_root / name / "_index.md").open("w") as f:
template_spec.render_template_to_file(MODULE_TEMPLATE_STRING, f)
Expand All @@ -104,7 +106,9 @@ def _recursive_create(data_root: dict, dir_root: Path, url_root: str, module_imp

elif kind == "class":
(dir_root / name).mkdir(exist_ok=True)
template_spec = TemplateReplacementSpec(name=name, link=name, parent=module_import_path.split(".")[-1])
template_spec = TemplateReplacementSpec(
name=name, link=name, parent=module_import_path.split(".")[-1], path=obj_module_import_path
)
with (dir_root / name / "_index.md").open("w") as f:
template_spec.render_template_to_file(CLASS_TEMPLATE_STRING, f)

Expand All @@ -118,7 +122,10 @@ def _recursive_create(data_root: dict, dir_root: Path, url_root: str, module_imp

with (dir_root / f"{func_name}.md").open("w") as f:
template_spec = TemplateReplacementSpec(
name=func_name, link=func_name, parent=module_import_path.split(".")[-1]
name=func_name,
link=func_name,
parent=module_import_path.split(".")[-1],
path=obj_module_import_path + f".{func_name}",
)
template_spec.render_template_to_file(FUNCTION_TEMPLATE_STRING, f)

Expand Down
16 changes: 10 additions & 6 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ for branch in "$remote_name/master" $(git branch -rl "$remote_name/rel/*") ; do
fi
API_GEN_FILE="$branch:scripts/docs/json_builder.py"
if git cat-file -e $API_GEN_FILE; then
echo "$API_GEN_FILE exists."
echo "Generating API ref..."
python3 ../scripts/docs/json_builder.py
mv -f data.json ./versioned_docs/
python3 ../scripts/docs/python_ref_builder.py ./versioned_docs/data.json ./versioned_docs/$target_section/api-reference --json_start_path sdk catalog --url_root "/$target_section/api-reference"
mv -f links.json ./versioned_docs/
echo "$API_GEN_FILE exists."
echo "Generating API ref..."
python3 ../scripts/docs/json_builder.py
mv -f data.json ./versioned_docs/
if [ "$target_section" == "" ] ; then
python3 ../scripts/docs/python_ref_builder.py ./versioned_docs/data.json ./versioned_docs/docs/api-reference --json_start_path sdk catalog --url_root "/docs/api-reference"
else
python3 ../scripts/docs/python_ref_builder.py ./versioned_docs/data.json ./versioned_docs/$target_section/api-reference --json_start_path sdk catalog --url_root "/$target_section/api-reference"
fi
mv -f links.json ./versioned_docs/
fi
done
if [ "$keep_master" != "keep_master" ] ; then
Expand Down

0 comments on commit 8f4514d

Please sign in to comment.