-
Notifications
You must be signed in to change notification settings - Fork 184
Add Python stub generation. #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extends the LVGL bindings generator to automatically create Python stub files (.pyi) that provide type hints and enable IDE autocompletion for LVGL MicroPython bindings. Features: - New -S/--stubs command line option for stub output directory - Comprehensive type mapping from C types to Python type hints - Single stub file with all widgets, functions, enums, and constants - Automatic generation during build process - Detailed documentation header with content statistics The generated lvgl.pyi file includes 40+ widget classes, 300+ functions, and comprehensive type information for better development experience. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…trings. - Rename first parameter from 'obj' to 'self' in class methods - Add comprehensive Doxygen comment parsing for LVGL documentation - Generate Python docstrings from C header comments - Add Self type hint for class method return values - Preserve original parameter names for static methods and functions - Load 200+ LVGL header files for documentation extraction - Format docstrings with Args and Returns sections - Exclude 'self' parameter from docstring Args section for class methods 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add proper text wrapping at ~85 characters for descriptions - Format return descriptions with dashes as bullet points - Maintain proper indentation for continuation lines in parameters - Use textwrap module for consistent line breaking - Handle long parameter descriptions with aligned wrapping - Improve readability of generated Python stub files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…strings. - Add missing textwrap import to fix NameError during stub generation - Preserve newline-separated bullet points in @return documentation - Handle both newline and space-separated bullet point formats - Improve parsing of multi-line return descriptions with proper formatting - Fix build error when generating Python stub files with documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…n stubs. Major performance improvements and build system changes: **Separate Build Target:** - Remove stub generation from main build (was slowing down normal builds) - Create optional lvgl-stubs target for documentation-enabled stub generation - Main build now completes quickly without documentation parsing overhead **Parallel Processing Optimizations:** - Add multiprocessing support using ProcessPoolExecutor - Process 200+ header files using all available CPU cores - Pre-build documentation index to eliminate repeated file searches - Progress reporting every 50 processed files - Graceful fallback to serial processing if parallel fails **Performance Results:** - Previous: Minutes for documentation parsing (blocking main build) - Current: ~6 seconds for 209 files and 1423 functions (separate target) - Uses all CPU cores efficiently with progress feedback - Documentation index built once, O(1) function lookup vs O(n) file search **Documentation Updates:** - Add comprehensive DOCSTRING_PARSING.md explaining the implementation - Document new build workflow and performance characteristics - Include usage examples for separate stub generation **Technical Changes:** - Replace load_lvgl_source_files() with parallel processing version - Add process_file_for_docs() for individual file processing - Change from source_files dict to doc_index for O(1) lookups - Update generate_class_stub() and generate_main_stub() signatures - Maintain backward compatibility with graceful error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Enhanced DOCSTRING_PARSING.md with complete overview and examples: **New Sections Added:** - Performance overview with key metrics (6 seconds, 1423 functions) - Real code examples showing generated stub content - IDE benefits and development impact - Parallel processing architecture details - Usage examples with bullet point formatting demonstrations **Content Improvements:** - Added emoji indicators for key features - Comprehensive technical details on parallel processing - Examples of class methods with self parameter handling - Bullet point return documentation examples - Performance comparisons and timing information **Documentation Structure:** - Overview with key features and performance metrics - Step-by-step technical implementation details - Real-world usage examples and IDE benefits - Complete technical architecture explanation - Development impact and benefits summary This provides complete documentation for the enhanced Python stub generation system with parallel processing and rich docstring extraction. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Updated examples and features list to demonstrate the new source reference functionality that includes file:line references in generated docstrings. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Closing this PR as it was created on master branch. Recreated as #388 from proper feature branch. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR implements comprehensive Python stub file (.pyi) generation for LVGL MicroPython bindings, providing full IDE support with autocompletion, type hints, and rich documentation extracted from LVGL C headers.
Key Features
Performance Improvements
Before:
After:
Generated Content Examples
Class Methods with Self Parameter and Source References:
Module Functions:
Technical Implementation
Parallel Processing Architecture:
Doxygen Comment Parsing:
Python Stub Generation:
Build System Changes
Main Build (Fast):
make USER_C_MODULES=../../lib/lvgl # No documentation parsing
Stub Generation (Separate):
cd lib/lvgl python3 gen/gen_mpy.py -M lvgl -MP lv -S output_dir -E preprocessed.pp lvgl/lvgl.h
Results
Testing
Trade-offs and Alternatives
Trade-offs:
Alternatives Considered:
Why This Approach:
Documentation
Added comprehensive documentation in
DOCSTRING_PARSING.md
covering:🤖 Generated with Claude Code