Skip to content

Commit

Permalink
Update the comm module
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Oct 20, 2022
1 parent 3767ce0 commit 57b76c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/xcomm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ namespace xpyt
.def(py::init<>())
.def("register_target", &xcomm_manager::register_target);

comm_module.def("create_comm", [&comm_module](py::args objs, py::kwargs kw) {
return comm_module.attr("Comm")(*objs, **kw);
});

comm_module.def("get_comm_manager", [&comm_module]() {
static py::object comm_manager = comm_module.attr("CommManager")();

return comm_manager;
});

return comm_module;
}

Expand Down
11 changes: 4 additions & 7 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ namespace xpyt
py::gil_scoped_acquire acquire;

py::module sys = py::module::import("sys");
py::module comm = py::module::import("comm");
py::module logging = py::module::import("logging");

py::module display_module = get_display_module();
Expand All @@ -74,12 +73,10 @@ namespace xpyt
py::module comm_module = get_comm_module();
py::module kernel_module = get_kernel_module();

// TODO Handle old ipywidgets by monkey patching ipykernel too...
comm.attr("register_comm_classes")(
comm_module.attr("Comm"),
comm_module.attr("CommManager")
);
m_comm_manager = comm.attr("create_comm_manager")();
// Old approach: ipykernel provides the comm
sys.attr("modules")["ipykernel.comm"] = comm_module;
// New approach: we provide our comm module
sys.attr("modules")["comm"] = comm_module;

instanciate_ipython_shell();

Expand Down

0 comments on commit 57b76c8

Please sign in to comment.