Skip to content

PyO3: Adds generate-stubs command#3115

Merged
messense merged 2 commits into
PyO3:mainfrom
Tpt:tpt/build-command
Apr 7, 2026
Merged

PyO3: Adds generate-stubs command#3115
messense merged 2 commits into
PyO3:mainfrom
Tpt:tpt/build-command

Conversation

@Tpt

@Tpt Tpt commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

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

@Tpt Tpt force-pushed the tpt/build-command branch from 3bb2520 to 7dec6fb Compare April 3, 2026 11:36
This builds the package in debug mode then tries to extract the generated stubs in a given target directory
@Tpt Tpt force-pushed the tpt/build-command branch from 7dec6fb to 7d9350b Compare April 3, 2026 11:55
@Tpt Tpt marked this pull request as ready for review April 3, 2026 15:07

@messense messense left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Tpt

Tpt commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

@messense Thank you! I implemented a slight tweak of your approach, exposing a BuildOrchestrator::generate_stubs method skips the archive generation internally. It felt less "spreading concerns" around. But glad to use your approach verbatim if you feel it's better.

@Tpt Tpt force-pushed the tpt/build-command branch from 220464d to 60313ca Compare April 7, 2026 09:46
@Tpt Tpt force-pushed the tpt/build-command branch from 60313ca to 7669473 Compare April 7, 2026 09:46

@messense messense left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@messense messense merged commit 83cb185 into PyO3:main Apr 7, 2026
44 of 45 checks passed
@Tpt Tpt deleted the tpt/build-command branch April 10, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants