From 866780b477a47aa53e53217a2af883923dfa337e Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 23 Dec 2024 14:11:38 -0500 Subject: [PATCH] x --- docs/_scripts/generate_api_reference_links.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/_scripts/generate_api_reference_links.py b/docs/_scripts/generate_api_reference_links.py index 714dc641f..8bc1f5e16 100644 --- a/docs/_scripts/generate_api_reference_links.py +++ b/docs/_scripts/generate_api_reference_links.py @@ -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 @@ -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) @@ -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]