stubgen: Fix generated stub filename when referencing out-of-director… #892
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…y extensions
Currently, to generate stubs for extensions not contained in the current directory, you have to invoke stubgen like so:
python -m nanobind.stubgen -m path.to.my.module -r -O ...
This is for example how I do it in nanobind-bazel, because Bazel invokes scripts from a hermetic "runfiles" directory, which is in general not the source directory.
In the recursive case, and possibly also the non-recursive case with an output directory specified, this leads to the creation of a file called
path.to.my.pyi
, which is not what we want (IDEs generally require that the stub file be of the same name as the generated module).Hence, in that case, we infer the stub file name as the last part of the module name given to stubgen.
Before:
and after:
This is a follow-up to nicholasjng/nanobind-bazel#44, where @cemlyn007 added recursive stubgen support to nanobind-bazel. He also kindly added a workaround for this problem there, but I would love to see it fixed upstream as well.
I would appreciate your opinion - for in-tree stub generation (i.e., the extension is contained in the current directory), this does not change anything, since then, the module name will not contain any dots.