diff --git a/src/xcomm.cpp b/src/xcomm.cpp index 6f74b2bd..5ec5e392 100644 --- a/src/xcomm.cpp +++ b/src/xcomm.cpp @@ -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; } diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index a5243078..45a750a5 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -73,8 +73,10 @@ namespace xpyt py::module comm_module = get_comm_module(); py::module kernel_module = get_kernel_module(); - // Monkey patching "from ipykernel.comm import Comm" + // 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();