Skip to content

Commit f3e9871

Browse files
committed
Upgrade to xeus 2.0.0
1 parent 172c6c1 commit f3e9871

10 files changed

+47
-33
lines changed

.appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install:
2727
- conda update -q conda
2828
- conda info -a
2929
# Host dependencies
30-
- conda install xeus=1.0.3 nlohmann_json cppzmq xtl "pybind11>=2.6.1,<3.0" "pybind11_json>=0.2.6,<0.3" gtest=1.8.0 debugpy "xeus-python-shell>=0.1.5,<2" "jupyter_client<=6.2" -c conda-forge
30+
- conda install xeus=2.0.0 nlohmann_json cppzmq xtl pybind11=2.6.0 pybind11_json=0.2.8 gtest=1.8.0 debugpy "xeus-python-shell>=0.1.5,<2" "jupyter_client<=6.2" -c conda-forge
3131
# Build dependencies
3232
- conda install cmake -c conda-forge
3333
# Build and install xeus-python

environment-dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dependencies:
55
# Build dependencies
66
- cmake
77
# Host dependencies
8-
- xeus=1.0.3
8+
- xeus=2.0.0
99
- nlohmann_json
1010
- cppzmq
1111
- xtl>=0.7, <0.8

include/xeus-python/xdebugger.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "zmq.hpp"
1919
#include "nlohmann/json.hpp"
20+
#include "xeus/xeus_context.hpp"
2021
#include "xeus/xdebugger_base.hpp"
2122
#include "xeus_python_config.hpp"
2223

@@ -61,7 +62,7 @@ namespace xpyt
6162
};
6263

6364
XEUS_PYTHON_API
64-
std::unique_ptr<xeus::xdebugger> make_python_debugger(zmq::context_t& context,
65+
std::unique_ptr<xeus::xdebugger> make_python_debugger(xeus::xcontext& context,
6566
const xeus::xconfiguration& config,
6667
const std::string& user_name,
6768
const std::string& session_id,

src/main.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
#include <unistd.h>
2222
#endif
2323

24+
#include "xeus/xeus_context.hpp"
2425
#include "xeus/xkernel.hpp"
2526
#include "xeus/xkernel_configuration.hpp"
26-
#include "xeus/xserver.hpp"
27+
#include "xeus/xserver_shell_main.hpp"
2728

2829
#include "pybind11/embed.h"
2930
#include "pybind11/pybind11.h"
@@ -155,6 +156,10 @@ int main(int argc, char* argv[])
155156
}
156157
delete[] argw;
157158

159+
using context_type = xeus::xcontext_impl<zmq::context_t>;
160+
using context_ptr = std::unique_ptr<context_type>;
161+
context_ptr context = context_ptr(new context_type());
162+
158163
// Instantiating the xeus xinterpreter
159164
using interpreter_ptr = std::unique_ptr<xpyt::interpreter>;
160165
interpreter_ptr interpreter = interpreter_ptr(new xpyt::interpreter());
@@ -180,11 +185,12 @@ int main(int argc, char* argv[])
180185

181186
xeus::xkernel kernel(config,
182187
xeus::get_user_name(),
188+
std::move(context),
183189
std::move(interpreter),
190+
xeus::make_xserver_shell_main,
184191
std::move(hist),
185192
xeus::make_console_logger(xeus::xlogger::msg_type,
186193
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")),
187-
xeus::make_xserver_shell_main,
188194
xpyt::make_python_debugger,
189195
debugger_config);
190196

@@ -199,10 +205,11 @@ int main(int argc, char* argv[])
199205
else
200206
{
201207
xeus::xkernel kernel(xeus::get_user_name(),
208+
std::move(context),
202209
std::move(interpreter),
210+
xeus::make_xserver_shell_main,
203211
std::move(hist),
204212
nullptr,
205-
xeus::make_xserver_shell_main,
206213
xpyt::make_python_debugger,
207214
debugger_config);
208215

src/xcomm.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace xpyt
4242

4343
using python_callback_type = std::function<void(py::object)>;
4444
using cpp_callback_type = std::function<void(const xeus::xmessage&)>;
45-
using zmq_buffers_type = std::vector<zmq::message_t>;
45+
using buffers_sequence = xeus::buffer_sequence;
4646

4747
xcomm(const py::args& args, const py::kwargs& kwargs);
4848
xcomm(xeus::xcomm&& comm);
@@ -83,7 +83,7 @@ namespace xpyt
8383
m_comm.open(
8484
kwargs.attr("get")("metadata", py::dict()),
8585
kwargs.attr("get")("data", py::dict()),
86-
pylist_to_zmq_buffers(kwargs.attr("get")("buffers", py::list()))
86+
pylist_to_cpp_buffers(kwargs.attr("get")("buffers", py::list()))
8787
);
8888
}
8989

@@ -111,7 +111,7 @@ namespace xpyt
111111
m_comm.close(
112112
kwargs.attr("get")("metadata", py::dict()),
113113
kwargs.attr("get")("data", py::dict()),
114-
pylist_to_zmq_buffers(kwargs.attr("get")("buffers", py::list()))
114+
pylist_to_cpp_buffers(kwargs.attr("get")("buffers", py::list()))
115115
);
116116
}
117117

@@ -120,7 +120,7 @@ namespace xpyt
120120
m_comm.send(
121121
kwargs.attr("get")("metadata", py::dict()),
122122
kwargs.attr("get")("data", py::dict()),
123-
pylist_to_zmq_buffers(kwargs.attr("get")("buffers", py::list()))
123+
pylist_to_cpp_buffers(kwargs.attr("get")("buffers", py::list()))
124124
);
125125
}
126126

src/xdebugger.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,13 @@ namespace xpyt
348348
return get_cell_tmp_file(code);
349349
}
350350

351-
std::unique_ptr<xeus::xdebugger> make_python_debugger(zmq::context_t& context,
351+
std::unique_ptr<xeus::xdebugger> make_python_debugger(xeus::xcontext& context,
352352
const xeus::xconfiguration& config,
353353
const std::string& user_name,
354354
const std::string& session_id,
355355
const nl::json& debugger_config)
356356
{
357-
return std::unique_ptr<xeus::xdebugger>(new debugger(context, config, user_name, session_id, debugger_config));
357+
return std::unique_ptr<xeus::xdebugger>(new debugger(context.get_wrapped_context<zmq::context_t>(),
358+
config, user_name, session_id, debugger_config));
358359
}
359360
}

src/xinternal_utils.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ namespace xpyt
3737
return py::module_::create_extension_module(module_name.c_str(), nullptr, new py::module_::module_def);
3838
}
3939

40-
zmq::message_t pybytes_to_zmq_message(py::bytes bytes)
40+
xeus::binary_buffer pybytes_to_cpp_message(py::bytes bytes)
4141
{
4242
char* buffer;
4343
Py_ssize_t length;
4444
PyBytes_AsStringAndSize(bytes.ptr(), &buffer, &length);
45-
return zmq::message_t(buffer, static_cast<std::size_t>(length));
45+
return xeus::binary_buffer(buffer, buffer + static_cast<std::size_t>(length));
4646
}
4747

48-
py::list zmq_buffers_to_pylist(const std::vector<zmq::message_t>& buffers)
48+
py::list cpp_buffers_to_pylist(const xeus::buffer_sequence& buffers)
4949
{
5050
py::list bufferlist;
51-
for (const zmq::message_t& buffer : buffers)
51+
for (const xeus::binary_buffer& buffer : buffers)
5252
{
53-
const char* buf = buffer.data<const char>();
53+
const char* buf = buffer.data();
5454
bufferlist.attr("append")(py::memoryview(py::bytes(buf)));
5555
}
5656
return bufferlist;
5757
}
5858

59-
std::vector<zmq::message_t> pylist_to_zmq_buffers(const py::object& bufferlist)
59+
xeus::buffer_sequence pylist_to_cpp_buffers(const py::object& bufferlist)
6060
{
61-
std::vector<zmq::message_t> buffers;
61+
xeus::buffer_sequence buffers;
6262

6363
// Cannot iterate over NoneType, returning immediately with an empty vector
6464
if (bufferlist.is_none())
@@ -71,11 +71,11 @@ namespace xpyt
7171
if (py::isinstance<py::memoryview>(buffer))
7272
{
7373
py::bytes bytes = buffer.attr("tobytes")();
74-
buffers.push_back(pybytes_to_zmq_message(bytes));
74+
buffers.push_back(pybytes_to_cpp_message(bytes));
7575
}
7676
else
7777
{
78-
buffers.push_back(pybytes_to_zmq_message(buffer.cast<py::bytes>()));
78+
buffers.push_back(pybytes_to_cpp_message(buffer.cast<py::bytes>()));
7979
}
8080
}
8181
return buffers;
@@ -88,7 +88,7 @@ namespace xpyt
8888
py_msg["parent_header"] = msg.parent_header().get<py::object>();
8989
py_msg["metadata"] = msg.metadata().get<py::object>();
9090
py_msg["content"] = msg.content().get<py::object>();
91-
py_msg["buffers"] = zmq_buffers_to_pylist(msg.buffers());
91+
py_msg["buffers"] = cpp_buffers_to_pylist(msg.buffers());
9292

9393
return py_msg;
9494
}

src/xinternal_utils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace xpyt
2525
{
2626
py::module create_module(const std::string& module_name);
2727

28-
py::list zmq_buffers_to_pylist(const std::vector<zmq::message_t>& buffers);
29-
std::vector<zmq::message_t> pylist_to_zmq_buffers(const py::object& bufferlist);
28+
py::list cpp_buffers_to_pylist(const xeus::buffer_sequence& buffers);
29+
xeus::buffer_sequence pylist_to_cpp_buffers(const py::object& bufferlist);
3030

3131
py::object cppmessage_to_pymessage(const xeus::xmessage& msg);
3232

src/xpython_extension.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
#include <string>
1414
#include <utility>
1515

16+
#include "xeus/xeus_context.hpp"
1617
#include "xeus/xkernel.hpp"
1718
#include "xeus/xkernel_configuration.hpp"
18-
#include "xeus/xserver.hpp"
19+
#include "xeus/xserver_shell_main.hpp"
1920

2021
#include "pybind11/pybind11.h"
2122

@@ -26,6 +27,10 @@ namespace py = pybind11;
2627

2728
void launch(const std::string& connection_filename)
2829
{
30+
using context_type = xeus::xcontext_impl<zmq::context_t>;
31+
using context_ptr = std::unique_ptr<context_type>;
32+
context_ptr context = context_ptr(new context_type());
33+
2934
// Instantiating the xeus xinterpreter
3035
using interpreter_ptr = std::unique_ptr<xpyt::interpreter>;
3136
interpreter_ptr interpreter = interpreter_ptr(new xpyt::interpreter());
@@ -46,11 +51,12 @@ void launch(const std::string& connection_filename)
4651

4752
xeus::xkernel kernel(config,
4853
xeus::get_user_name(),
54+
std::move(context),
4955
std::move(interpreter),
56+
xeus::make_xserver_shell_main,
5057
std::move(hist),
5158
xeus::make_console_logger(xeus::xlogger::msg_type,
5259
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")),
53-
xeus::make_xserver_shell_main,
5460
xpyt::make_python_debugger);
5561

5662
std::clog <<
@@ -64,10 +70,11 @@ void launch(const std::string& connection_filename)
6470
else
6571
{
6672
xeus::xkernel kernel(xeus::get_user_name(),
73+
std::move(context),
6774
std::move(interpreter),
75+
xeus::make_xserver_shell_main,
6876
std::move(hist),
6977
nullptr,
70-
xeus::make_xserver_shell_main,
7178
xpyt::make_python_debugger);
7279

7380
const auto& config = kernel.get_config();

test/xeus_client.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "xeus/xguid.hpp"
2020
#include "xeus/xmessage.hpp"
2121
#include "xeus/xmiddleware.hpp"
22+
#include "xeus/xzmq_serializer.hpp"
2223

2324
using namespace std::chrono_literals;
2425

@@ -107,8 +108,7 @@ nl::json xeus_client_base::receive_on_iopub()
107108
{
108109
zmq::multipart_t wire_msg;
109110
wire_msg.recv(m_iopub);
110-
xeus::xpub_message msg;
111-
msg.deserialize(wire_msg, *p_iopub_authentication);
111+
xeus::xpub_message msg = xeus::xzmq_serializer::deserialize_iopub(wire_msg, *p_iopub_authentication);
112112

113113
nl::json res = aggregate(msg.header(),
114114
msg.parent_header(),
@@ -130,14 +130,13 @@ void xeus_client_base::send_message(nl::json header,
130130
zmq::socket_t& socket,
131131
const xeus::xauthentication& auth)
132132
{
133-
zmq::multipart_t wire_msg;
134133
xeus::xmessage msg(xeus::xmessage::guid_list(),
135134
std::move(header),
136135
std::move(parent_header),
137136
std::move(metadata),
138137
std::move(content),
139138
xeus::buffer_sequence());
140-
std::move(msg).serialize(wire_msg, auth);
139+
zmq::multipart_t wire_msg = xeus::xzmq_serializer::serialize(std::move(msg), auth);
141140
wire_msg.send(socket);
142141
}
143142

@@ -146,8 +145,7 @@ nl::json xeus_client_base::receive_message(zmq::socket_t& socket,
146145
{
147146
zmq::multipart_t wire_msg;
148147
wire_msg.recv(socket);
149-
xeus::xmessage msg;
150-
msg.deserialize(wire_msg, auth);
148+
xeus::xmessage msg = xeus::xzmq_serializer::deserialize(wire_msg, auth);
151149

152150
return aggregate(msg.header(),
153151
msg.parent_header(),

0 commit comments

Comments
 (0)