Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Dec 23, 2024
1 parent 4b0c53f commit 866780b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docs/_scripts/generate_api_reference_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from typing import List, Literal, Optional
from typing_extensions import TypedDict


from functools import lru_cache

import nbformat
from nbconvert.preprocessors import Preprocessor

Expand Down Expand Up @@ -85,8 +88,11 @@ def _make_regular_expression(pkg_prefix: str) -> re.Pattern:
_IMPORT_LANGGRAPH_RE = _make_regular_expression("langgraph")


def _get_full_module_name(module_path, class_name) -> Optional[str]:
"""Get full module name using inspect"""


@lru_cache(maxsize=10_000)
def _get_full_module_name(module_path: str, class_name: str) -> Optional[str]:
"""Get full module name using inspect, with LRU cache to memoize results."""
try:
module = importlib.import_module(module_path)
class_ = getattr(module, class_name)
Expand All @@ -97,13 +103,12 @@ def _get_full_module_name(module_path, class_name) -> Optional[str]:
return module_path
return module.__name__
except AttributeError as e:
logger.warning(f"Could not find module for {class_name}, {e}")
logger.warning(f"API Reference: Could not find module for {class_name}, {e}")
return None
except ImportError as e:
logger.warning(f"Failed to load for class {class_name}, {e}")
logger.warning(f"API Reference: Failed to load for class {class_name}, {e}")
return None


def _get_doc_title(data: str, file_name: str) -> str:
try:
return re.findall(r"^#\s*(.*)", data, re.MULTILINE)[0]
Expand Down

0 comments on commit 866780b

Please sign in to comment.