Skip to content

Commit

Permalink
qx
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Dec 23, 2024
1 parent f993dfc commit 8213e47
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
35 changes: 0 additions & 35 deletions docs/_scripts/generate_api_reference_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,6 @@ def _get_imports(
return imports


class ImportPreprocessor(Preprocessor):
"""A preprocessor to replace imports in each Python code cell with links to their
documentation and append the import info in a comment."""

def preprocess(self, nb, resources):
self.all_imports = []
file_name = os.path.basename(resources.get("metadata", {}).get("name", ""))
_DOC_TITLE = _get_doc_title(nb.cells[0].source, file_name)

cells = []
for cell in nb.cells:
if cell.cell_type == "code":
cells.append(cell)
imports = _get_imports(
cell.source, _DOC_TITLE, "langchain"
) + _get_imports(cell.source, _DOC_TITLE, "langgraph")
if not imports:
continue

cells.append(
nbformat.v4.new_markdown_cell(
source=f"""
<div>
<b>API Reference:</b>
{' | '.join(f'<a href="{imp["docs"]}">{imp["imported"]}</a>' for imp in imports)}
</div>
"""
)
)
else:
cells.append(cell)
nb.cells = cells
return nb, resources


def get_imports(code: str, doc_title: str) -> List[ImportInformation]:
"""Retrieve all import references from the given code for specified ecosystems.
Expand Down
1 change: 0 additions & 1 deletion docs/_scripts/notebook_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def preprocess_cell(self, cell, resources, cell_index):
preprocessors=[
EscapePreprocessor,
ExtractAttachmentsPreprocessor,
ImportPreprocessor,
],
template_name="mdoutput",
extra_template_basedirs=[
Expand Down
8 changes: 3 additions & 5 deletions docs/_scripts/notebook_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ def on_page_markdown(markdown: str, page: Page, **kwargs: Dict[str, Any]):
if page.file.src_path.endswith(".ipynb"):
logger.info("Processing Jupyter notebook: %s", page.file.src_path)
markdown = convert_notebook(page.file.abs_src_path)
else:
# Append API reference links to code blocks
# This logic is already applied for notebooks in `convert_notebook`.
# We add it here to apply it to regular markdown files.
markdown = update_markdown_with_imports(markdown)

# Append API reference links to code blocks
markdown = update_markdown_with_imports(markdown)
# Apply highlight comments to code blocks
markdown = _highlight_code_blocks(markdown)
return markdown

0 comments on commit 8213e47

Please sign in to comment.