Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Bazel recursive stubgen example #54

Open
wants to merge 6 commits into
base: bazel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: recursive example
  • Loading branch information
cemlyn007 committed Nov 17, 2024
commit 847d700290d6d36201dfa7e722fcccd5c9ac98cb
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def bazel_build(self, ext: BazelExtension) -> None:
should_copy = True

if should_copy:
new_directory = libdir / os.path.relpath(root, srcdir)
if not os.path.exists(new_directory):
os.mkdir(new_directory)
shutil.copyfile(root / fp, libdir / new_directory / fp)
dstdir = libdir / os.path.relpath(root, srcdir)
nicholasjng marked this conversation as resolved.
Show resolved Hide resolved
if not os.path.exists(dstdir):
os.mkdir(dstdir)
shutil.copyfile(root / fp, dstdir / fp)


setuptools.setup(
Expand Down
4 changes: 3 additions & 1 deletion src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load(

py_library(
name = "nanobind_example",
srcs = ["nanobind_example/__init__.py"],
srcs = ["nanobind_example/__init__.py", "nanobind_example/sub_ext/__init__.py"],
data = [":nanobind_example_ext"],
visibility = ["//visibility:public"],
)
Expand All @@ -20,4 +20,6 @@ nanobind_stubgen(
name = "nanobind_example_ext_stubgen",
module = ":nanobind_example_ext",
marker_file = "src/py.typed",
output_directory = "src",
recursive = True,
)
1 change: 1 addition & 0 deletions src/nanobind_example/sub_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ..nanobind_example_ext.sub_ext import sub
nicholasjng marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions src/nanobind_example_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ using namespace nb::literals;
NB_MODULE(nanobind_example_ext, m) {
m.doc() = "This is a \"hello world\" example with nanobind";
m.def("add", [](int a, int b) { return a + b; }, "a"_a, "b"_a);

nb::module_ sm = m.def_submodule("sub_ext", "A submodule of 'nanobind_example_ext'");

sm.def("sub", [](int a, int b) { return a - b; }, "a"_a, "b"_a);
}