Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Resolve mypy type-checking issues in docs generation files #621

Merged
merged 80 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
54c0918
WIP
harishmohanraj Jan 6, 2025
ce23c21
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 7, 2025
1c42c7f
updated mako template
harishmohanraj Jan 7, 2025
b5539ee
WIP
harishmohanraj Jan 7, 2025
fea0eb2
Update meko template
harishmohanraj Jan 7, 2025
af3f108
Update meko template
harishmohanraj Jan 7, 2025
2edce7d
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 8, 2025
460d957
Use pdoc3 for generating the API docs
harishmohanraj Jan 8, 2025
7132ddc
Fix the generated docs/reference directory structure
harishmohanraj Jan 8, 2025
f01c166
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 8, 2025
6c2f7b1
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 8, 2025
76e6326
Polishing
harishmohanraj Jan 8, 2025
205af71
polishing
harishmohanraj Jan 8, 2025
4aa7838
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 9, 2025
ea67ce1
Remove setup.py
harishmohanraj Jan 9, 2025
fee0a3b
Remove docs-requirement file
harishmohanraj Jan 9, 2025
d6c939f
Polishing
harishmohanraj Jan 9, 2025
a76271e
Polishing
harishmohanraj Jan 9, 2025
5752ac3
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 10, 2025
7cdd985
Docs test
harishmohanraj Jan 13, 2025
892c92e
Docs test
harishmohanraj Jan 13, 2025
ea85b87
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 17, 2025
4f473c3
Fix broken links
harishmohanraj Jan 17, 2025
b7c212a
Merge pull request #84 from harishmohanraj/fix-broken-lins
harishmohanraj Jan 17, 2025
1696039
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 17, 2025
f240870
Merge remote-tracking branch 'origin/main' into split-api-reference
harishmohanraj Jan 17, 2025
58aaf26
Remove docs extra from dev
harishmohanraj Jan 17, 2025
e0d6d51
Add missing packages
harishmohanraj Jan 17, 2025
80b27b2
Remove redundant command
harishmohanraj Jan 17, 2025
9c6fa56
Add returns section to docs
harishmohanraj Jan 17, 2025
8dea4a6
Update docs
harishmohanraj Jan 17, 2025
8af9004
Merge pull request #85 from harishmohanraj/split-api-reference
harishmohanraj Jan 17, 2025
c64669c
Update python version in workflow file
harishmohanraj Jan 17, 2025
dd5e5d9
Pass OPENAI_API_KEY in CI
harishmohanraj Jan 17, 2025
88a4749
Merge pull request #86 from harishmohanraj/fix-workflow
harishmohanraj Jan 17, 2025
efbc97f
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 17, 2025
22544ae
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 20, 2025
4cd3d84
Fix review comments
harishmohanraj Jan 20, 2025
22fb9a7
Remove docs from dev extra
harishmohanraj Jan 20, 2025
ff4c92f
Add quotes around each packahe name
harishmohanraj Jan 20, 2025
4701e27
Polishing
harishmohanraj Jan 20, 2025
9a98378
Merge pull request #87 from harishmohanraj/review-fixes
harishmohanraj Jan 20, 2025
2268ff8
WIP
harishmohanraj Jan 20, 2025
873c9d9
Merge remote-tracking branch 'upstream/main' into fix-upstream-conflicts
harishmohanraj Jan 21, 2025
8d3a14d
Merge pull request #88 from harishmohanraj/fix-upstream-conflicts
harishmohanraj Jan 21, 2025
0ce5377
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 21, 2025
303729f
WIP
harishmohanraj Jan 21, 2025
553353b
Merge remote-tracking branch 'upstream/main' into fix-upstream-conflicts
harishmohanraj Jan 21, 2025
e0d7e90
Merge pull request #89 from harishmohanraj/fix-upstream-conflicts
harishmohanraj Jan 21, 2025
0684195
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 21, 2025
94b0551
Merge remote-tracking branch 'upstream/main' into fix-upstream-confli…
harishmohanraj Jan 21, 2025
6fa3103
Merge pull request #90 from harishmohanraj/fix-upstream-conflicts-1
harishmohanraj Jan 21, 2025
4cb404e
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 21, 2025
e19e63c
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 22, 2025
a9798de
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 22, 2025
4ba27cf
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 22, 2025
0f24d8d
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 22, 2025
c56f3eb
Fix missed import in file
kumaranvpl Jan 22, 2025
fe5b0a7
Fix missed third party imports in arxiv files
kumaranvpl Jan 22, 2025
155002c
Merge remote-tracking branch 'upstream/fix-random-import' into review…
harishmohanraj Jan 22, 2025
63cd4f1
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 22, 2025
f108c1f
Merge remote-tracking branch 'origin/main' into review-fixes
harishmohanraj Jan 22, 2025
a8de9c9
Add jinja in docs dependency
harishmohanraj Jan 22, 2025
656e35e
Cleanup
harishmohanraj Jan 22, 2025
5bf4c07
Merge pull request #91 from harishmohanraj/review-fixes
harishmohanraj Jan 22, 2025
b94f498
Polishing
harishmohanraj Jan 22, 2025
75468ad
Merge pull request #92 from harishmohanraj/polishing
harishmohanraj Jan 22, 2025
8bba256
wip
davorrunje Jan 22, 2025
7f64df7
WIP
harishmohanraj Jan 22, 2025
536efe5
Merge remote-tracking branch 'upstream/main' into fix-upstream-confli…
harishmohanraj Jan 22, 2025
9af6fd0
Merge pull request #93 from harishmohanraj/fix-upstream-conflicts-2
harishmohanraj Jan 22, 2025
758c0ad
Merge remote-tracking branch 'origin/main' into mypy-check
harishmohanraj Jan 22, 2025
cd28bd7
Fix mypy issues
harishmohanraj Jan 22, 2025
3d07c39
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 22, 2025
06fa746
Merge remote-tracking branch 'origin/main' into mypy-check
harishmohanraj Jan 22, 2025
08264ba
fix typos
harishmohanraj Jan 22, 2025
0750314
Merge pull request #94 from harishmohanraj/mypy-check
harishmohanraj Jan 22, 2025
cda251b
Merge branch 'ag2ai:main' into main
harishmohanraj Jan 22, 2025
f32e0a6
pre-commit fixed
davorrunje Jan 22, 2025
4e807ec
Merge pull request #95 from harishmohanraj/mypy-check
harishmohanraj Jan 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,22 @@ exclude = "(.eggs|.git|.hg|.mypy_cache|.venv|_build|buck-out|build|dist)"
fix = true
line-length = 120
target-version = 'py39'
#include = ["autogen", "test", "docs"]
exclude = ["setup_*.py"]
# Exclude a variety of commonly ignored directories.
exclude = [
".eggs",
".git",
".mypy_cache",
".ruff_cache",
"__pypackages__",
"_build",
"build",
"dist",
"docs",
# This file needs to be either upgraded or removed and therefore should be
# ignore from type checking for now
"math_utils\\.py$",
"setup_*.py",
]

[tool.ruff.lint]
# Enable Pyflakes `E` and `F` codes by default.
Expand Down Expand Up @@ -305,21 +319,6 @@ ignore = ["E501", "F403", "C901",
"D100", "D101", "D102", "D103", "D104",
"C901", # too complex
]
# Exclude a variety of commonly ignored directories.
exclude = [
".eggs",
".git",
".mypy_cache",
".ruff_cache",
"__pypackages__",
"_build",
"build",
"dist",
"docs",
# This file needs to be either upgraded or removed and therefore should be
# ignore from type checking for now
"math_utils\\.py$",
]

[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
Expand Down Expand Up @@ -348,6 +347,7 @@ files = [
"autogen/agentchat/realtime_agent",
"autogen/messages",
"autogen/import_utils.py",
"website/*.py",
"test/test_pydantic.py",
"test/io",
"test/tools",
Expand All @@ -357,6 +357,7 @@ files = [
"test/conftest.py",
"test/test_import_utils.py",
"test/test_import.py",
"test/website",
]

exclude = [
Expand Down
29 changes: 16 additions & 13 deletions test/website/test_process_api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
import sys
import tempfile
from pathlib import Path
from typing import Generator

import pytest

# Add the ../../website directory to sys.path
sys.path.append(str(Path(__file__).resolve().parent.parent.parent / "website"))
website_path = Path(__file__).resolve().parents[2] / "website"
assert website_path.exists()
assert website_path.is_dir()
sys.path.append(str(website_path))

from process_api_reference import generate_mint_json_from_template, move_files_excluding_index


def create_test_directory_structure(tmp_path):
@pytest.fixture
def api_dir(tmp_path: Path) -> Path:
"""Helper function to create test directory structure"""
# Create autogen directory
autogen_dir = tmp_path / "autogen"
Expand Down Expand Up @@ -48,11 +54,8 @@ def create_test_directory_structure(tmp_path):
return tmp_path


def test_move_files_excluding_index(tmp_path):
def test_move_files_excluding_index(api_dir: Path) -> None:
"""Test that files are moved correctly excluding index.md"""
# Setup the test directory structure
api_dir = create_test_directory_structure(tmp_path)

# Call the function under test
move_files_excluding_index(api_dir)

Expand All @@ -79,7 +82,7 @@ def test_move_files_excluding_index(tmp_path):


@pytest.fixture
def template_content():
def template_content() -> str:
"""Fixture providing the template JSON content."""
template = """
{
Expand All @@ -103,14 +106,14 @@ def template_content():


@pytest.fixture
def temp_dir():
def temp_dir() -> Generator[Path, None, None]:
"""Fixture providing a temporary directory."""
with tempfile.TemporaryDirectory() as tmp_dir:
yield Path(tmp_dir)


@pytest.fixture
def template_file(temp_dir, template_content):
def template_file(temp_dir: Path, template_content: str) -> Path:
"""Fixture creating a template file in a temporary directory."""
template_path = temp_dir / "mint-json-template.json.jinja"
with open(template_path, "w") as f:
Expand All @@ -119,12 +122,12 @@ def template_file(temp_dir, template_content):


@pytest.fixture
def target_file(temp_dir):
def target_file(temp_dir: Path) -> Path:
"""Fixture providing the target mint.json path."""
return temp_dir / "mint.json"


def test_generate_mint_json_from_template(template_file, target_file, template_content):
def test_generate_mint_json_from_template(template_file: Path, target_file: Path, template_content: str) -> None:
"""Test that mint.json is generated correctly from template."""
# Run the function
generate_mint_json_from_template(template_file, target_file)
Expand All @@ -140,7 +143,7 @@ def test_generate_mint_json_from_template(template_file, target_file, template_c
assert actual == expected


def test_generate_mint_json_existing_file(template_file, target_file, template_content):
def test_generate_mint_json_existing_file(template_file: Path, target_file: Path, template_content: str) -> None:
"""Test that function works when mint.json already exists."""
# Create an existing mint.json with different content
existing_content = {"name": "existing"}
Expand All @@ -158,7 +161,7 @@ def test_generate_mint_json_existing_file(template_file, target_file, template_c
assert actual == expected


def test_generate_mint_json_missing_template(target_file):
def test_generate_mint_json_missing_template(target_file: Path) -> None:
"""Test handling of missing template file."""
with tempfile.TemporaryDirectory() as tmp_dir:
nonexistent_template = Path(tmp_dir) / "nonexistent.template"
Expand Down
29 changes: 15 additions & 14 deletions test/website/test_process_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import textwrap
from pathlib import Path
from typing import Generator, Optional, Union

import pytest

Expand All @@ -24,7 +25,7 @@
)


def test_ensure_mint_json():
def test_ensure_mint_json() -> None:
# Test with empty temp directory - should raise SystemExit
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
Expand All @@ -36,7 +37,7 @@ def test_ensure_mint_json():
ensure_mint_json_exists(tmp_path) # Should not raise any exception


def test_cleanup_tmp_dirs_if_no_metadata():
def test_cleanup_tmp_dirs_if_no_metadata() -> None:
# Test without the tmp_dir / "snippets" / "data" / "NotebooksMetadata.mdx"
# the tmp_dir / "notebooks" should be removed.
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -68,8 +69,8 @@ def test_cleanup_tmp_dirs_if_no_metadata():


class TestAddFrontMatterToMetadataMdx:
def test_without_metadata_mdx(self):
front_matter_dict = {
def test_without_metadata_mdx(self) -> None:
front_matter_dict: dict[str, Union[str, Optional[Union[list[str]]]]] = {
"title": "some title",
"link": "/notebooks/some-title",
"description": "some description",
Expand Down Expand Up @@ -118,8 +119,8 @@ def test_without_metadata_mdx(self):
"""
)

def test_with_metadata_mdx(self):
front_matter_dict = {
def test_with_metadata_mdx(self) -> None:
front_matter_dict: dict[str, Optional[Union[str, Union[list[str]]]]] = {
"title": "some title",
"link": "/notebooks/some-title",
"description": "some description",
Expand Down Expand Up @@ -203,7 +204,7 @@ def test_with_metadata_mdx(self):

class TestAddBlogsToNavigation:
@pytest.fixture
def test_dir(self):
def test_dir(self) -> Generator[Path, None, None]:
"""Create a temporary directory with test files."""
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
Expand Down Expand Up @@ -231,7 +232,7 @@ def test_dir(self):
yield tmp_path

@pytest.fixture
def expected(self):
def expected(self) -> list[str]:
return [
"blog/2024-12-20-Tools-interoperability/index",
"blog/2024-12-20-RetrieveChat/index",
Expand All @@ -246,11 +247,11 @@ def expected(self):
"blog/2023-04-21-LLM-tuning-math/index",
]

def test_get_sorted_files(self, test_dir, expected):
def test_get_sorted_files(self, test_dir: Path, expected: list[str]) -> None:
actual = get_sorted_files(test_dir, "blog")
assert actual == expected, actual

def test_add_blogs_to_navigation(self):
def test_add_blogs_to_navigation(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
website_dir = Path(tmp_dir)
blog_dir = website_dir / "blog"
Expand Down Expand Up @@ -374,7 +375,7 @@ def setup(self, temp_dir: Path) -> None:
with open(metadata_path, "w", encoding="utf-8") as f:
f.write(notebooks_metadata_content)

def test_extract_example_group(self):
def test_extract_example_group(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
self.setup(tmp_path)
Expand Down Expand Up @@ -403,7 +404,7 @@ def test_extract_example_group(self):

class TestAddAuthorsAndSocialImgToBlogPosts:
@pytest.fixture
def test_dir(self):
def test_dir(self) -> Generator[Path, None, None]:
"""Create temporary test directory with blog posts and authors file."""
with tempfile.TemporaryDirectory() as tmp_dir:
website_dir = Path(tmp_dir)
Expand Down Expand Up @@ -534,7 +535,7 @@ def test_dir(self):

yield website_dir

def test_add_authors_and_social_img(self, test_dir):
def test_add_authors_and_social_img(self, test_dir: Path) -> None:
# Run the function
add_authors_and_social_img_to_blog_posts(test_dir)

Expand Down Expand Up @@ -682,6 +683,6 @@ def expected(self) -> str:
This is a conclusion.
""")

def test_convert_callout_blocks(self, content: str, expected: str) -> str:
def test_convert_callout_blocks(self, content: str, expected: str) -> None:
actual = convert_callout_blocks(content)
assert actual == expected, actual
10 changes: 5 additions & 5 deletions website/process_api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import subprocess
import sys
from pathlib import Path
from typing import Any
from typing import Any, Optional

from jinja2 import Template

Expand Down Expand Up @@ -55,7 +55,7 @@ def run_pdoc3(api_dir: Path) -> None:
sys.exit(1)


def read_file_content(file_path: str) -> str:
def read_file_content(file_path: Path) -> str:
"""Read content from a file.

Args:
Expand Down Expand Up @@ -108,15 +108,15 @@ def get_mdx_files(directory: Path) -> list[str]:
return [f"{p.relative_to(directory).with_suffix('')!s}".replace("\\", "/") for p in directory.rglob("*.mdx")]


def add_prefix(path: str, parent_groups: list[str] = None) -> str:
def add_prefix(path: str, parent_groups: Optional[list[str]] = None) -> str:
"""Create full path with prefix and parent groups."""
groups = parent_groups or []
return f"docs/reference/{'/'.join(groups + [path])}"


def create_nav_structure(paths: list[str], parent_groups: list[str] = None) -> list[Any]:
def create_nav_structure(paths: list[str], parent_groups: Optional[list[str]] = None) -> list[Any]:
"""Convert list of file paths into nested navigation structure."""
groups = {}
groups: dict[str, list[str]] = {}
pages = []
parent_groups = parent_groups or []

Expand Down
Loading
Loading