# Test basic tree generation
print(generate_tree(show_notebooks_only=True))nbs/
├── api_docs.ipynb
├── cli.ipynb
├── core.ipynb
├── dependencies.ipynb
├── generators.ipynb
├── parsers.ipynb
└── tree.ipynb
First, let’s implement the basic tree generation without descriptions:
Strip Markdown links from text, keeping only the link text
def generate_tree_lines(
path:Path, # Directory to visualize
prefix:str='', # Line prefix for tree structure
is_last:bool=True, # Is this the last item in parent
show_notebooks_only:bool=False, # Only show notebooks, not directories
max_depth:Optional[int]=None, # Maximum depth to traverse
current_depth:int=0, # Current depth in traversal
exclude_index:bool=True, # Exclude index.ipynb from tree
exclude_empty:bool=True, # Exclude empty directories
)->List[str]: # Lines of tree output
Generate tree visualization lines for a directory
def generate_tree(
path:Path=None, # Directory to visualize (defaults to nbs_path)
show_notebooks_only:bool=False, # Only show notebooks, not directories
max_depth:Optional[int]=None, # Maximum depth to traverse
exclude_index:bool=True, # Exclude index.ipynb from tree
exclude_empty:bool=True, # Exclude empty directories
)->str: # Tree visualization as string
Generate a tree visualization for a directory
Let’s test the basic tree generation on our project:
Now let’s add functions to extract descriptions from notebooks:
Extract title and description from a notebook
Title: Core Utilities
Description: Core utilities and data models for nbdev project overview generation
Export module: core
Now let’s create the enhanced tree generation that includes descriptions:
def generate_tree_with_descriptions(
path:Path=None, # Directory to visualize
show_counts:bool=True, # Show notebook counts for directories
max_depth:Optional[int]=None, # Maximum depth to traverse
exclude_index:bool=True, # Exclude index.ipynb from tree
exclude_empty:bool=True, # Exclude empty directories
)->str: # Tree with descriptions
Generate tree visualization with descriptions from notebooks
Let’s test the enhanced tree on our project:
Let’s test that Markdown links are properly stripped from descriptions:
# Test the strip_markdown_links function
test_cases = [
"Buttons allow the user to take actions or make choices. [daisyUI docs](https://daisyui.com/components/button/)",
"A simple description with no links",
"Multiple [link one](http://example.com) and [link two](http://example.com/2) in text",
"[Link at start](http://example.com) of description"
]
print("Testing strip_markdown_links function:")
for test in test_cases:
result = strip_markdown_links(test)
print(f"\nOriginal: {test}")
print(f"Stripped: {result}")Testing strip_markdown_links function:
Original: Buttons allow the user to take actions or make choices. [daisyUI docs](https://daisyui.com/components/button/)
Stripped: Buttons allow the user to take actions or make choices. daisyUI docs
Original: A simple description with no links
Stripped: A simple description with no links
Original: Multiple [link one](http://example.com) and [link two](http://example.com/2) in text
Stripped: Multiple link one and link two in text
Original: [Link at start](http://example.com) of description
Stripped: Link at start of description
nbs/
├── api_docs.ipynb # Generate module overviews with formatted signatures for nbdev projects
├── cli.ipynb # CLI commands for nbdev project overview generation and analysis
├── core.ipynb # Core utilities and data models for nbdev project overview generation
├── dependencies.ipynb # Analyze cross-notebook imports and generate Mermaid.js dependency diagrams
├── generators.ipynb # Auto-generate folder_name.ipynb notebooks for nbdev project organization
├── parsers.ipynb # Parse notebook metadata, content, and extract function/class signatures with docments
└── tree.ipynb # Generate tree visualizations for nbdev project structure
Let’s also add a function to visualize a specific subdirectory with its notebooks:
Generate tree visualization for a specific subdirectory showing all notebooks
Let’s add a function to generate summary statistics:
Get summary statistics for notebooks in directory tree