Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your change:
This PR extensively refactors build_directory_md.py to align with PEP 8 standards, introduce modern type hinting, and significantly improve code readability, documentation, and maintainability. The core functionality—generating a Markdown Table of Contents from Python source files—remains the same.
Explanation of code:
#!/usr/bin/env python3
"""
A utility script to generate a Markdown-formatted table of contents
for Python-related files (.py, .ipynb) in a specified directory structure.
It excludes common project utility folders and hidden directories.
"""
import os
import re
from typing import Iterator, Set
Define directories to exclude during os.walk traversal
EXCLUDED_DIRS: Set[str] = {"scripts", "venv", "pycache"}
def good_file_paths(top_dir: str = ".") -> Iterator[str]:
"""
Recursively walks the directory structure, yielding file paths for
Python files (.py, .ipynb), while skipping excluded directories and
init.py files.
def _generate_markdown_prefix(indent_level: int) -> str:
"""
Generates the appropriate Markdown prefix for directory levels or file entries.
def format_name(name: str) -> str:
"""
Converts a file/directory name (e.g., 'my_awesome_file') into a Title Case
string, replacing underscores with spaces (e.g., 'My Awesome File').
"""
return name.replace('', ' ').title()
def print_directory_md(top_dir: str = ".") -> None:
"""
Generates and prints a Markdown table of contents for the file structure
starting at top_dir.
if name == "main":
print_directory_md()
###Reviewer Notes: Please verify that the output structure remains consistent with the expected hierarchical Markdown list and that file exclusion logic is correct.