Skip to content

Add option for supplying stub dependencies at build time#1336

Open
r-dean wants to merge 1 commit into
wjakob:masterfrom
r-dean:add-stubgen-dep-flag
Open

Add option for supplying stub dependencies at build time#1336
r-dean wants to merge 1 commit into
wjakob:masterfrom
r-dean:add-stubgen-dep-flag

Conversation

@r-dean
Copy link
Copy Markdown

@r-dean r-dean commented May 6, 2026

Add --dep flag for build-time stub generation with module dependencies

Currently, projects with multiple interdependent extension modules are forced to use INSTALL_TIME stub generation (or a hacky workaround), because build-time generation has no mechanism to handle modules that depend on other modules.

I generally prefer to keep as much stuff at build time as possible as I find it keeps things more modular and debuggable. For sufficiently complex projects moving everything to install time might be the way to go, but in my usage I've found that I just want to express one or two binding modules that another depends on.

This PR adds a --dep PATH=NAME flag to stubgen (and a corresponding MODULE_DEP parameter to nanobind_add_stub()) that loads a dependency module from a file path and registers it under a provided name. This allows build-time stub generation to work correctly for multi-module projects.

Example usage

nanobind_add_stub(
    child_stubs
    MODULE child_ext
    OUTPUT child_ext.pyi
    DEPENDS child_ext base_ext
    MODULE_DEP $<TARGET_FILE:base_ext>=my_package.base_ext
)

Tests

Includes test modules (test_dep_base_ext, test_dep_other_ext, test_dep_child_ext) that exercise cross-module inheritance and multiple dependencies with MODULE_DEP. All existing stub tests continue to pass.

@r-dean r-dean marked this pull request as draft May 6, 2026 00:31
@r-dean r-dean marked this pull request as ready for review May 6, 2026 00:52
@r-dean r-dean marked this pull request as draft May 6, 2026 00:54
@r-dean r-dean force-pushed the add-stubgen-dep-flag branch from 7b9c321 to aef1a82 Compare May 6, 2026 01:10
@r-dean r-dean marked this pull request as ready for review May 6, 2026 01:15
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.

1 participant