Skip to content

Commit

Permalink
Use jinja template for generating the mint json file
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Jan 22, 2025
1 parent 103a8c7 commit 0d391ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
35 changes: 16 additions & 19 deletions test/website/test_process_api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
@pytest.fixture
def template_content():
"""Fixture providing the template JSON content."""
return {
template = """
{
"name": "AG2",
"logo": {"dark": "/logo/ag2-white.svg", "light": "/logo/ag2.svg"},
"navigation": [
Expand All @@ -27,20 +28,14 @@ def template_content():
"pages": [
"docs/installation/Installation",
"docs/installation/Docker",
"docs/installation/Optional-Dependencies",
],
"docs/installation/Optional-Dependencies"
]
},
{"group": "API Reference", "pages": ["PLACEHOLDER"]},
# {
# "group": "AutoGen Studio",
# "pages": [
# "docs/autogen-studio/getting-started",
# "docs/autogen-studio/usage",
# "docs/autogen-studio/faqs",
# ],
# },
],
{"group": "API Reference", "pages": ["PLACEHOLDER"]}
]
}
"""
return template


@pytest.fixture
Expand All @@ -53,9 +48,9 @@ def temp_dir():
@pytest.fixture
def template_file(temp_dir, template_content):
"""Fixture creating a template file in a temporary directory."""
template_path = temp_dir / "mint-json-template.json"
template_path = temp_dir / "mint-json-template.json.jinja"
with open(template_path, "w") as f:
json.dump(template_content, f, indent=2)
f.write(template_content)
return template_path


Expand All @@ -75,9 +70,10 @@ def test_generate_mint_json_from_template(template_file, target_file, template_c

# Verify the contents
with open(target_file) as f:
generated_content = json.load(f)
actual = json.load(f)

assert generated_content == template_content
expected = json.loads(template_content)
assert actual == expected


def test_generate_mint_json_existing_file(template_file, target_file, template_content):
Expand All @@ -92,9 +88,10 @@ def test_generate_mint_json_existing_file(template_file, target_file, template_c

# Verify the contents were overwritten
with open(target_file) as f:
generated_content = json.load(f)
actual = json.load(f)

assert generated_content == template_content
expected = json.loads(template_content)
assert actual == expected


def test_generate_mint_json_missing_template(target_file):
Expand Down
File renamed without changes.
13 changes: 10 additions & 3 deletions website/process_api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from pathlib import Path
from typing import Any

from jinja2 import Template


def run_pydoc_markdown(config_file: Path) -> None:
"""Run pydoc-markdown with the specified config file.
Expand Down Expand Up @@ -179,10 +181,15 @@ def generate_mint_json_from_template(mint_json_template_path: Path, mint_json_pa
os.remove(mint_json_path)

# Copy the template file to mint.json
mint_json_template_content = read_file_content(mint_json_template_path)
contents = read_file_content(mint_json_template_path)
mint_json_template_content = Template(contents).render()

# Parse the rendered template content as JSON
mint_json_data = json.loads(mint_json_template_content)

# Write content to mint.json
write_file_content(mint_json_path, mint_json_template_content)
with open(mint_json_path, "w") as f:
json.dump(mint_json_data, f, indent=2)


def main() -> None:
Expand All @@ -208,7 +215,7 @@ def main() -> None:
convert_md_to_mdx(args.api_dir)

# Create mint.json from the template file
mint_json_template_path = script_dir / "mint-json-template.json"
mint_json_template_path = script_dir / "mint-json-template.json.jinja"
mint_json_path = script_dir / "mint.json"

print("Generating mint.json from template...")
Expand Down

0 comments on commit 0d391ec

Please sign in to comment.