1111import re
1212import sys
1313from pathlib import Path
14- from typing import Dict , List , Optional , Tuple
1514
1615try :
1716 import nbformat
2928 Image = None # type: ignore[assignment,misc]
3029
3130
32- def load_categories_from_index (index_path : Path ) -> Dict [str , List [str ]]:
31+ def load_categories_from_index (index_path : Path ) -> dict [str , list [str ]]:
3332 """
3433 Load category structure from existing index.md.
3534
@@ -39,10 +38,10 @@ def load_categories_from_index(index_path: Path) -> Dict[str, List[str]]:
3938
4039 Returns
4140 -------
42- Dict [str, List [str]]
41+ dict [str, list [str]]
4342 Mapping from category name to list of notebook names (without .ipynb)
4443 """
45- categories : Dict [str , List [str ]] = {}
44+ categories : dict [str , list [str ]] = {}
4645 current_category = None
4746
4847 if not index_path .exists ():
@@ -69,7 +68,7 @@ def load_categories_from_index(index_path: Path) -> Dict[str, List[str]]:
6968 return categories
7069
7170
72- def get_notebook_category (filename : str , category_mapping : Dict [str , List [str ]]) -> str :
71+ def get_notebook_category (filename : str , category_mapping : dict [str , list [str ]]) -> str :
7372 """Determine the category for a notebook from the loaded mapping."""
7473 notebook_name = filename .replace (".ipynb" , "" )
7574 for category , notebooks in category_mapping .items ():
@@ -78,7 +77,7 @@ def get_notebook_category(filename: str, category_mapping: Dict[str, List[str]])
7877 return "Other"
7978
8079
81- def extract_metadata (notebook_path : Path ) -> Tuple [str , str ]:
80+ def extract_metadata (notebook_path : Path ) -> tuple [str , str ]:
8281 """Extract title and description from notebook."""
8382 with open (notebook_path , "r" , encoding = "utf-8" ) as f :
8483 nb = nbformat .read (f , as_version = 4 )
@@ -124,7 +123,7 @@ def extract_metadata(notebook_path: Path) -> Tuple[str, str]:
124123 return title , description
125124
126125
127- def extract_first_image (notebook_path : Path , output_dir : Path ) -> Optional [ str ] :
126+ def extract_first_image (notebook_path : Path , output_dir : Path ) -> str | None :
128127 """Extract first image from notebook outputs (without executing if outputs exist)."""
129128 if Image is None :
130129 return None
@@ -188,7 +187,7 @@ def extract_first_image(notebook_path: Path, output_dir: Path) -> Optional[str]:
188187
189188def _save_thumbnail (
190189 notebook_path : Path , output_dir : Path , image_data : str
191- ) -> Optional [ str ] :
190+ ) -> str | None :
192191 """Save thumbnail image from base64 data."""
193192 try :
194193 thumbnail_name = f"{ notebook_path .stem } .png"
@@ -225,13 +224,13 @@ def _save_thumbnail(
225224
226225
227226def generate_gallery_markdown (
228- notebooks_data : List [ Dict ],
227+ notebooks_data : list [ dict ],
229228 output_path : Path ,
230- category_mapping : Dict [str , List [str ]],
229+ category_mapping : dict [str , list [str ]],
231230):
232231 """Generate gallery markdown file with sphinx-design cards."""
233232 # Group notebooks by category
234- categories : Dict [str , List [ Dict ]] = {}
233+ categories : dict [str , list [ dict ]] = {}
235234 for nb_data in notebooks_data :
236235 category = nb_data ["category" ]
237236 if category not in categories :
0 commit comments