[REFACTOR][STUBGEN] refactor the stubgen logic. (#608)
## Summary
This PR refactors the Python stubgen implementation to improve
extensibility and separation of concerns. No functional changes are
intended, and the generated output should remain unchanged.
## Design
The current stubgen implementation contains both language-independent
logic (e.g., file processing and library analysis) and language-specific
code generation. This PR separates these responsibilities by introducing
a generator abstraction for the code generation layer, making it easier
to support additional target languages in the future.
The reorganized file structure is:
```text
python/tvm_ffi/stub/
├── __init__.py
├── cli.py
├── consts.py
├── file_utils.py
├── lib_state.py
├── utils.py
├── generator.py
└── python_generator/
├── __init__.py
├── generator.py
├── codegen.py
├── consts.py
└── utils.py
```
This refactoring lays the groundwork for future support of Rust stub
generation and other language backends.
## Testing
This PR is a pure refactor and is not expected to change existing
behavior. Therefore, no new tests are added.
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>📚 Documentation | 🚀 Quickstart
Apache TVM FFI is an open ABI and FFI for machine learning systems. It is a minimal, framework-agnostic, yet flexible open convention with the following systems in mind:
These enable broad interoperability across frameworks, libraries, DSLs, and agents; the ability to ship one wheel for multiple frameworks and Python versions (including free-threaded Python); and consistent infrastructure across environments.
Install TVM-FFI with pip, uv or from source:
pip install apache-tvm-ffi pip install torch-c-dlpack-ext # compatibility package for torch <= 2.9
C ABI stability is our top priority.
Status: RFC Main features are complete and ABI stable. We recognize potential needs for evolution to ensure it works best for the machine learning systems community, and would like to work together with the community for such evolution. We plan to stay in the RFC stage for three months from the v0.1.0 release.
Releases during the RFC stage will be 0.X.Y, where bumps in X indicate C ABI-breaking changes and Y indicates other changes. We anticipate the RFC stage will last for three months, then we will start following Semantic Versioning (major.minor.patch) going forward.
Our documentation site includes: