gemini-code-assist[bot] commented on PR #259:
URL: https://github.com/apache/tvm-ffi/pull/259#issuecomment-3525470319
## Summary of Changes
This pull request introduces a substantial refactoring and enhancement of
the `tvm-ffi-stubgen` tool. The primary goal is to improve the robustness,
maintainability, and functionality of the stub generation process, with a
particular focus on handling import statements and type mappings more
effectively. By modularizing the code generation logic and standardizing
formatting, the tool now produces more accurate and well-formatted type stubs
for Python modules that integrate with the TVM FFI ecosystem.
### Highlights
* **Refactored Stub Generation Logic**: The core logic of the
`tvm-ffi-stubgen` tool has been significantly refactored, with responsibilities
distributed across new modules (`codegen.py`, `consts.py`, `file_utils.py`) to
improve organization and maintainability.
* **Enhanced Import Generation**: The stub generator now includes dedicated
logic for automatically generating and managing import statements, ensuring
that all necessary types are correctly imported and formatted within the
generated stub files.
* **Improved Type Mapping and Handling**: New `tvm-ffi-stubgen(ty-map)`
directives and a more robust type mapping mechanism have been introduced,
allowing for flexible and accurate resolution of type aliases in the generated
stubs.
* **Standardized Formatting Directives**: `fmt: off/on` and `isort: off/on`
directives are now consistently applied around generated code blocks, ensuring
proper formatting and linting compliance for the output stubs.
* **Updated CLI Options**: The `stubgen` command-line interface has been
enhanced with new `--verbose` and `--dry-run` options, providing better
debugging capabilities and allowing users to preview changes before applying
them.
<details>
<summary><b>Changelog</b></summary>
* **pyproject.toml**
* Added a mypy override to skip import checking for `_pytest.*` modules.
* **python/tvm_ffi/_ffi_api.py**
* Wrapped import statements within a `tvm-ffi-stubgen(begin): import`
block, including `fmt: off` and `isort: off/on` directives.
* Adjusted `fmt: off` placement for global FFI definitions.
* **python/tvm_ffi/access_path.py**
* Introduced a `tvm-ffi-stubgen(begin): import` block with formatting
directives for imports.
* Added `tvm-ffi-stubgen(ty-map)` directives for `AccessStep` and
`AccessPath` classes.
* Refactored object stub generation to remove `if TYPE_CHECKING:`
wrapper around field definitions and updated method signatures to use `self`.
* **python/tvm_ffi/module.py**
* Added a `tvm-ffi-stubgen(begin): import` block with formatting
directives for imports.
* Refactored object stub generation to remove `if TYPE_CHECKING:`
wrapper around field definitions.
* **python/tvm_ffi/stub/codegen.py**
* New file: Implements core code generation functions for function
signatures, global functions, object types, and import statements.
* **python/tvm_ffi/stub/consts.py**
* New file: Defines constants for stub generation markers, terminal
colors, default extensions, and type mapping.
* **python/tvm_ffi/stub/file_utils.py**
* New file: Provides utilities for parsing and managing file content and
code blocks, including diff generation and file updates.
* **python/tvm_ffi/stub/stubgen.py**
* Replaced the extensive module docstring with a
`tvm-ffi-stubgen(skip-file)` marker and a concise docstring.
* Refactored the main logic to utilize the new `codegen`, `consts`, and
`file_utils` modules.
* Updated `Options` dataclass with `verbose` and `dry_run` flags.
* Modified argument parsing to include new CLI options.
* **python/tvm_ffi/testing.py**
* Added a `tvm-ffi-stubgen(begin): import` block with formatting
directives for imports.
* Added `tvm-ffi-stubgen(ty-map)` directive for `_SchemaAllTypes`.
* Refactored object stub generation to remove `if TYPE_CHECKING:`
wrapper around field definitions and updated method signatures to use `self`.
* **tests/python/test_stubgen.py**
* Removed the entire test file for `stubgen`.
</details>
<details>
<summary><b>Activity</b></summary>
* The author, junrushao, initiated a `/gemini summarize` command, requesting
an automated summary of the pull request.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]