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

WIP: Upgrade to Xeus 4.0 #622

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3f99d8d
Update context
IsabelParedes Mar 27, 2024
20c3c9e
Add parent header
IsabelParedes Mar 28, 2024
c063c5a
Add request context to display
IsabelParedes Mar 28, 2024
aedb575
Add request context to raw interpreter
IsabelParedes Mar 28, 2024
b2c7452
Set nljson version
IsabelParedes Apr 17, 2024
b1d1bfa
Update execute request signature
IsabelParedes Apr 17, 2024
50a96da
Update execute request
IsabelParedes Apr 18, 2024
6235c0c
Update publish execution result
IsabelParedes Apr 18, 2024
a35e41a
Partial update blocking input request
IsabelParedes Apr 18, 2024
ec37dfc
Include request context header
IsabelParedes Apr 18, 2024
b783fed
Remove parent header from kernel
IsabelParedes Apr 18, 2024
28d17a9
Remove sockets
IsabelParedes Apr 18, 2024
25c5942
Fix context request
IsabelParedes Apr 19, 2024
5f5a00f
Add request context to publish execution
IsabelParedes Apr 19, 2024
46f96de
Propagate request context in display
IsabelParedes Apr 19, 2024
b927c0c
Update clear output
IsabelParedes Apr 19, 2024
8342a8c
Propagate request context to displayhook
IsabelParedes Apr 19, 2024
8ad5164
Fix typo
IsabelParedes Apr 19, 2024
df08c4a
More request context
IsabelParedes Apr 19, 2024
0a65375
Use config
IsabelParedes Apr 19, 2024
eec7024
Propagate context
IsabelParedes Apr 19, 2024
cd10119
Fix typo
IsabelParedes Apr 19, 2024
133def0
Fix cpp function arguments
IsabelParedes Apr 19, 2024
9672415
Add context to publish display
IsabelParedes Apr 19, 2024
12168f1
Fix typo
IsabelParedes Apr 19, 2024
952536c
Fix internal request context
IsabelParedes Apr 19, 2024
a088f86
Fix channel
IsabelParedes Apr 19, 2024
a5ce310
Propagate context
IsabelParedes Apr 22, 2024
b2f0ec7
Update xcomm
IsabelParedes Apr 22, 2024
f1de5c5
Propagate more context
IsabelParedes Apr 22, 2024
4cbf881
Fix progressbar init
IsabelParedes Apr 22, 2024
03f0ac3
Add parent header
IsabelParedes Apr 22, 2024
9c8e9fc
Update context and headers
IsabelParedes Apr 22, 2024
3fe785c
Fix debugger context
IsabelParedes Apr 24, 2024
a520a94
Fixed server include in main
JohanMabille Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions environment-dev.yml
Expand Up @@ -7,9 +7,9 @@ dependencies:
- cxx-compiler
- ninja
# Host dependencies
- xeus>=4.0.2
- xeus-zmq>=1.3.0,<2.0
- nlohmann_json
- cppzmq
- nlohmann_json=3.11.3
- xtl>=0.7, <0.8
- pybind11>=2.6.1,<3.0
- pybind11_json>=0.2.6,<0.3
Expand Down
10 changes: 3 additions & 7 deletions include/xeus-python/xdebugger.hpp
Expand Up @@ -20,9 +20,7 @@
#include <mutex>
#include <set>

#include "zmq.hpp"
#include "nlohmann/json.hpp"
#include "xeus/xeus_context.hpp"
#include "pybind11/pybind11.h"
#include "xeus-zmq/xdebugger_base.hpp"
#include "xeus_python_config.hpp"
Expand All @@ -40,7 +38,7 @@ namespace xpyt

using base_type = xeus::xdebugger_base;

debugger(zmq::context_t& context,
debugger(xeus::xcontext& context,
const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
Expand All @@ -59,10 +57,8 @@ namespace xpyt
nl::json variables_request_impl(const nl::json& message) override;

bool start_debugpy();
bool start(zmq::socket_t& header_socket,
zmq::socket_t& request_socket) override;
void stop(zmq::socket_t& header_socket,
zmq::socket_t& request_socket) override;
bool start() override;
void stop() override;
xeus::xdebugger_info get_debugger_info() const override;
std::string get_cell_temporary_file(const std::string& code) const override;

Expand Down
15 changes: 8 additions & 7 deletions include/xeus-python/xinterpreter.hpp
Expand Up @@ -22,6 +22,7 @@
#include "nlohmann/json.hpp"

#include "xeus/xinterpreter.hpp"
#include "xeus/xrequest_context.hpp"

#include "pybind11/pybind11.h"

Expand Down Expand Up @@ -51,12 +52,12 @@ namespace xpyt

void configure_impl() override;

nl::json execute_request_impl(int execution_counter,
const std::string& code,
bool silent,
bool store_history,
nl::json user_expressions,
bool allow_stdin) override;
void execute_request_impl(xeus::xrequest_context request_context,
send_reply_callback cb,
int execution_counter,
const std::string& code,
xeus::execute_request_config config,
nl::json user_expressions) override;

nl::json complete_request_impl(const std::string& code, int cursor_pos) override;

Expand Down Expand Up @@ -99,7 +100,7 @@ namespace xpyt

private:

virtual void instanciate_ipython_shell();
virtual void instantiate_ipython_shell();
};
}

Expand Down
13 changes: 7 additions & 6 deletions include/xeus-python/xinterpreter_raw.hpp
Expand Up @@ -20,6 +20,7 @@
#include "nlohmann/json.hpp"

#include "xeus/xinterpreter.hpp"
#include "xeus/xrequest_context.hpp"

#include "pybind11/pybind11.h"

Expand Down Expand Up @@ -49,12 +50,12 @@ namespace xpyt

void configure_impl() override;

nl::json execute_request_impl(int execution_counter,
const std::string& code,
bool silent,
bool store_history,
nl::json user_expressions,
bool allow_stdin) override;
void execute_request_impl(xeus::xrequest_context request_context,
send_reply_callback cb,
int execution_counter,
const std::string& code,
xeus::execute_request_config config,
nl::json user_expressions) override;

nl::json complete_request_impl(const std::string& code, int cursor_pos) override;

Expand Down
8 changes: 3 additions & 5 deletions src/main.cpp
Expand Up @@ -21,12 +21,12 @@
#include <unistd.h>
#endif

#include "xeus/xeus_context.hpp"
#include "xeus/xkernel.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus/xinterpreter.hpp"

#include "xeus-zmq/xserver_shell_main.hpp"
#include "xeus-zmq/xserver_zmq_split.hpp"
#include "xeus-zmq/xzmq_context.hpp"

#include "pybind11/embed.h"
#include "pybind11/pybind11.h"
Expand Down Expand Up @@ -99,9 +99,7 @@ int main(int argc, char* argv[])
}
delete[] argw;

using context_type = xeus::xcontext_impl<zmq::context_t>;
using context_ptr = std::unique_ptr<context_type>;
context_ptr context = context_ptr(new context_type());
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();

// Instantiating the xeus xinterpreter
bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv);
Expand Down
43 changes: 35 additions & 8 deletions src/xcomm.cpp
Expand Up @@ -37,10 +37,13 @@ namespace xpyt
* xcomm implementation *
************************/

xcomm::xcomm(const py::object& target_name, const py::object& data, const py::object& metadata, const py::object& buffers, const py::kwargs& kwargs)
xcomm::xcomm(const py::object& target_name,
const py::object& data,
const py::object& metadata,
const py::object& buffers,
const py::kwargs& kwargs)
: m_comm(target(target_name), id(kwargs))
{
m_comm.open(metadata, data, pylist_to_cpp_buffers(buffers));
}

xcomm::xcomm(xeus::xcomm&& comm)
Expand All @@ -62,14 +65,28 @@ namespace xpyt
return true;
}

void xcomm::close(const py::object& data, const py::object& metadata, const py::object& buffers)
void xcomm::open(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers)
{
m_comm.close(metadata, data, pylist_to_cpp_buffers(buffers));
m_comm.open(parent_header, metadata, data, pylist_to_cpp_buffers(buffers));
}

void xcomm::send(const py::object& data, const py::object& metadata, const py::object& buffers)
void xcomm::close(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers)
{
m_comm.send(metadata, data, pylist_to_cpp_buffers(buffers));
m_comm.close(parent_header, metadata, data, pylist_to_cpp_buffers(buffers));
}

void xcomm::send(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers)
{
m_comm.send(parent_header, metadata, data, pylist_to_cpp_buffers(buffers));
}

void xcomm::on_msg(const python_callback_type& callback)
Expand Down Expand Up @@ -133,8 +150,18 @@ namespace xpyt
py::init<const py::object&, const py::object&, const py::object&, const py::object&, py::kwargs>(),
"target_name"_a="", "data"_a=py::dict(), "metadata"_a=py::dict(), "buffers"_a=py::list()
)
.def("close", &xcomm::close, "data"_a=py::dict(), "metadata"_a=py::dict(), "buffers"_a=py::list())
.def("send", &xcomm::send, "data"_a=py::dict(), "metadata"_a=py::dict(), "buffers"_a=py::list())
.def("open", &xcomm::open, "parent_header"_a=py::dict(),
"data"_a=py::dict(),
"metadata"_a=py::dict(),
"buffers"_a=py::list())
.def("close", &xcomm::close, "parent_header"_a=py::dict(),
"data"_a=py::dict(),
"metadata"_a=py::dict(),
"buffers"_a=py::list())
.def("send", &xcomm::send, "parent_header"_a=py::dict(),
"data"_a=py::dict(),
"metadata"_a=py::dict(),
"buffers"_a=py::list())
.def("on_msg", &xcomm::on_msg)
.def("on_close", &xcomm::on_close)
.def_property_readonly("comm_id", &xcomm::comm_id)
Expand Down
25 changes: 21 additions & 4 deletions src/xcomm.hpp
Expand Up @@ -23,18 +23,35 @@ namespace xpyt

using python_callback_type = std::function<void(py::object)>;
using cpp_callback_type = std::function<void(const xeus::xmessage&)>;
using buffers_sequence = xeus::buffer_sequence;

xcomm(const py::object& target_name, const py::object& data, const py::object& metadata, const py::object& buffers, const py::kwargs& kwargs);
xcomm(const py::object& target_name,
const py::object& data,
const py::object& metadata,
const py::object& buffers,
const py::kwargs& kwargs);

xcomm(xeus::xcomm&& comm);
xcomm(xcomm&& comm) = default;
virtual ~xcomm();

std::string comm_id() const;
bool kernel() const;

void close(const py::object& data, const py::object& metadata, const py::object& buffers);
void send(const py::object& data, const py::object& metadata, const py::object& buffers);
void open(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers);

void close(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers);

void send(const py::object& parent_header,
const py::object& data,
const py::object& metadata,
const py::object& buffers);

void on_msg(const python_callback_type& callback);
void on_close(const python_callback_type& callback);

Expand Down
21 changes: 8 additions & 13 deletions src/xdebugger.cpp
Expand Up @@ -42,7 +42,7 @@ using namespace std::placeholders;

namespace xpyt
{
debugger::debugger(zmq::context_t& context,
debugger::debugger(xeus::xcontext& context,
const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
Expand Down Expand Up @@ -305,7 +305,7 @@ namespace xpyt
return status == "ok";
}

bool debugger::start(zmq::socket_t& header_socket, zmq::socket_t& request_socket)
bool debugger::start()
{
std::string temp_dir = xeus::get_temp_directory_path();
std::string log_dir = temp_dir + "/" + "xpython_debug_logs_" + std::to_string(xeus::get_current_pid());
Expand All @@ -322,8 +322,7 @@ namespace xpyt
std::string controller_header_end_point = xeus::get_controller_end_point("debugger_header");
std::string publisher_end_point = xeus::get_publisher_end_point();

request_socket.bind(controller_end_point);
header_socket.bind(controller_header_end_point);
bind_sockets(controller_end_point, controller_header_end_point);

std::string debugpy_end_point = "tcp://" + m_debugpy_host + ':' + m_debugpy_port;
std::thread client(&xdap_tcp_client::start_debugger,
Expand All @@ -334,22 +333,19 @@ namespace xpyt
controller_header_end_point);
client.detach();

request_socket.send(zmq::message_t("REQ", 3), zmq::send_flags::none);
zmq::message_t ack;
(void)request_socket.recv(ack);
send_recv_request("REQ");

std::string tmp_folder = get_tmp_prefix();
std::string tmp_folder = get_tmp_prefix();
xeus::create_directory(tmp_folder);

return true;
}

void debugger::stop(zmq::socket_t& header_socket, zmq::socket_t& request_socket)
void debugger::stop()
{
std::string controller_end_point = xeus::get_controller_end_point("debugger");
std::string controller_header_end_point = xeus::get_controller_end_point("debugger_header");
request_socket.unbind(controller_end_point);
header_socket.unbind(controller_header_end_point);
unbind_sockets(controller_end_point, controller_header_end_point);
}

xeus::xdebugger_info debugger::get_debugger_info() const
Expand All @@ -373,7 +369,6 @@ namespace xpyt
const std::string& session_id,
const nl::json& debugger_config)
{
return std::unique_ptr<xeus::xdebugger>(new debugger(context.get_wrapped_context<zmq::context_t>(),
config, user_name, session_id, debugger_config));
return std::unique_ptr<xeus::xdebugger>(new debugger(context, config, user_name, session_id, debugger_config));
}
}
3 changes: 1 addition & 2 deletions src/xdebugpy_client.cpp
Expand Up @@ -8,7 +8,6 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "zmq_addon.hpp"
#include "nlohmann/json.hpp"
#include "xeus/xmessage.hpp"
#include "xdebugpy_client.hpp"
Expand All @@ -20,7 +19,7 @@ namespace nl = nlohmann;

namespace xpyt
{
xdebugpy_client::xdebugpy_client(zmq::context_t& context,
xdebugpy_client::xdebugpy_client(xeus::xcontext& context,
const xeus::xconfiguration& config,
int socket_linger,
const xdap_tcp_configuration& dap_config,
Expand Down
2 changes: 1 addition & 1 deletion src/xdebugpy_client.hpp
Expand Up @@ -25,7 +25,7 @@ namespace xpyt
using base_type = xdap_tcp_client;
using event_callback = base_type::event_callback;

xdebugpy_client(zmq::context_t& context,
xdebugpy_client(xeus::xcontext& context,
const xeus::xconfiguration& config,
int socket_linger,
const xdap_tcp_configuration& dap_config,
Expand Down