PyO3: Adds generate-stubs command#3115
Conversation
This builds the package in debug mode then tries to extract the generated stubs in a given target directory
There was a problem hiding this comment.
Thanks for the PR! One suggestion: the current approach builds a full wheel into a temp dir, then re-opens the ZIP to extract .pyi files. This is a wasteful round-trip.
The compile_cdylib method in BuildOrchestrator (line 665 of build_orchestrator.rs) already provides a clean separation — it compiles and stages the artifact before write_wheel packages it. We could expose a public compile_artifact (or similar) method that stops after compilation, e.g.:
/// Compile the cdylib artifact without packaging it into a wheel.
pub fn compile_artifact(
&self,
python_interpreter: Option<&PythonInterpreter>,
) -> Result<(BuildArtifact, HashMap<String, PathBuf>)> {
self.compile_cdylib(python_interpreter, None)
}Then generate-stubs could load the compiled .so/.dylib directly via the binding generator to extract stubs, skipping wheel creation and the temp dir + ZIP overhead entirely.
|
@messense Thank you! I implemented a slight tweak of your approach, exposing a |
This builds the package in debug mode then tries to extract the generated stubs in a given target directory
I plan to add (in a follow up?) better error messages but wanted to get feedback first