From b33908f5dc41ddbdee5c9d0c19dcdff786a5f3c4 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 09:55:41 +0100 Subject: [PATCH 01/23] Fix context errors --- include/xeus-python/xdebugger.hpp | 2 +- src/main.cpp | 7 +++---- src/xdebugger.cpp | 5 +++-- src/xdebugpy_client.cpp | 3 ++- src/xdebugpy_client.hpp | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index 1b06fbab..ba0ff3e9 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -40,7 +40,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, diff --git a/src/main.cpp b/src/main.cpp index de81bf39..3e482314 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,8 @@ #include "xeus/xkernel_configuration.hpp" #include "xeus/xinterpreter.hpp" -#include "xeus-zmq/xserver_shell_main.hpp" +#include "xeus-zmq/xserver_zmq.hpp" +#include "xeus-zmq/xzmq_context.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -99,9 +100,7 @@ int main(int argc, char* argv[]) } delete[] argw; - using context_type = xeus::xcontext_impl; - using context_ptr = std::unique_ptr; - context_ptr context = context_ptr(new context_type()); + auto context = xeus::make_zmq_context(); // Instantiating the xeus xinterpreter bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv); diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index 967f004f..f264a595 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -26,6 +26,7 @@ #include "pybind11/stl.h" #include "xeus/xinterpreter.hpp" +#include "xeus/xeus_context.hpp" #include "xeus/xsystem.hpp" #include "xeus-zmq/xmiddleware.hpp" @@ -42,7 +43,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, @@ -373,7 +374,7 @@ namespace xpyt const std::string& session_id, const nl::json& debugger_config) { - return std::unique_ptr(new debugger(context.get_wrapped_context(), + return std::unique_ptr(new debugger(context.get_wrapped_context(), config, user_name, session_id, debugger_config)); } } diff --git a/src/xdebugpy_client.cpp b/src/xdebugpy_client.cpp index 3addabbf..44b43a36 100644 --- a/src/xdebugpy_client.cpp +++ b/src/xdebugpy_client.cpp @@ -11,6 +11,7 @@ #include "zmq_addon.hpp" #include "nlohmann/json.hpp" #include "xeus/xmessage.hpp" +#include "xeus/xeus_context.hpp" #include "xdebugpy_client.hpp" #include @@ -20,7 +21,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, diff --git a/src/xdebugpy_client.hpp b/src/xdebugpy_client.hpp index e9c59fbb..aec9e4e5 100644 --- a/src/xdebugpy_client.hpp +++ b/src/xdebugpy_client.hpp @@ -12,6 +12,7 @@ #define XPYT_DEBUGPY_CLIENT_HPP #include "xeus-zmq/xdap_tcp_client.hpp" +#include "xeus/xeus_context.hpp" namespace xpyt { @@ -25,7 +26,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, From 0adb618b016fb2feafb6482ff8dd3b51549c8977 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 11:50:29 +0100 Subject: [PATCH 02/23] Working build --- src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3e482314..ec797122 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,11 @@ #include #endif +#ifndef UVW_AS_LIB +#define UVW_AS_LIB +#include +#endif + #include "xeus/xeus_context.hpp" #include "xeus/xkernel.hpp" #include "xeus/xkernel_configuration.hpp" @@ -84,8 +89,35 @@ int main(int argc, char* argv[]) xpyt::set_pythonhome(); xpyt::print_pythonhome(); - // Instanciating the Python interpreter - py::scoped_interpreter guard; + // Instantiating the Python interpreter + py::scoped_interpreter guard{}; + + uv_loop_t* uv_loop_ptr{ nullptr }; + + { + py::gil_scoped_acquire acquire; + + // Instantiating the loop manually + py::exec(R"( + import asyncio + import uvloop + from uvloop.loop import libuv_get_loop_t_ptr + + print('Creating uvloop event loop') + loop = uvloop.new_event_loop() + asyncio.set_event_loop(loop) + print('uvloop event loop created') + )"); + + py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr()"); + void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); + if (!raw_ptr) + throw std::runtime_error("Failed to get libuv loop pointer"); + + uv_loop_ptr = static_cast(raw_ptr); + } + + auto loop_ptr = uvw::loop::create(uv_loop_ptr); // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; @@ -130,6 +162,12 @@ int main(int argc, char* argv[]) nl::json debugger_config; debugger_config["python"] = executable; + auto make_xserver = [loop_ptr](xeus::xcontext& context, + const xeus::xconfiguration& config, + nl::json::error_handler_t eh) { + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); + }; + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -138,7 +176,7 @@ int main(int argc, char* argv[]) xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), @@ -158,7 +196,7 @@ int main(int argc, char* argv[]) xeus::xkernel kernel(xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), nullptr, xpyt::make_python_debugger, From 7ec1dcec6d5fe7df2c93c8fd2dea924cf1ea6d18 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 12:56:43 +0100 Subject: [PATCH 03/23] Working without debugger The debugger causes zmq errors somewhere --- src/main.cpp | 31 +++++++++++++++++++++++-------- src/xinterpreter.cpp | 1 + 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ec797122..10857372 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,8 +94,8 @@ int main(int argc, char* argv[]) uv_loop_t* uv_loop_ptr{ nullptr }; - { - py::gil_scoped_acquire acquire; + // { + // py::gil_scoped_acquire acquire; // Instantiating the loop manually py::exec(R"( @@ -109,16 +109,27 @@ int main(int argc, char* argv[]) print('uvloop event loop created') )"); - py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr()"); + py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr(loop)"); void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); if (!raw_ptr) + { + std::cout << "Got null pointer!\n"; throw std::runtime_error("Failed to get libuv loop pointer"); + } uv_loop_ptr = static_cast(raw_ptr); - } + std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; + // } + if (!uv_loop_ptr) + { + throw std::runtime_error("Failed to get libuv loop pointer"); + std::cout << "This pointer is no good\n"; + } auto loop_ptr = uvw::loop::create(uv_loop_ptr); + std::cout << "Got a loop!\n"; + // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; for(auto i = 0; i < argc; ++i) @@ -155,19 +166,23 @@ int main(int argc, char* argv[]) #ifdef XEUS_PYTHON_PYPI_WARNING std::clog << "WARNING: this instance of xeus-python has been installed from a PyPI wheel.\n" - "We recommend using a general-purpose package manager instead, such as Conda/Mamba.\n" + "We recommend using a ge7yuneral-purpose package manager instead, such as Conda/Mamba.\n" << std::endl; #endif nl::json debugger_config; debugger_config["python"] = executable; + std::cout << "Making a server\n"; + auto make_xserver = [loop_ptr](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); }; + std::cout << "Done with the lambda\n"; + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -179,9 +194,9 @@ int main(int argc, char* argv[]) make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, - xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), - xpyt::make_python_debugger, - debugger_config); + xeus::make_file_logger(xeus::xlogger::content, "xeus.log"))); + // xpyt::make_python_debugger, + // debugger_config); std::clog << "Starting xeus-python kernel...\n\n" diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 0078d5eb..761a3123 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -182,6 +182,7 @@ namespace xpyt kernel_res["traceback"] = error.m_traceback; } + kernel_res["status"] = "error"; return kernel_res; } From 71cf45cd4912aee392f83fddc2daeaf5b6f7fafd Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 11 Mar 2024 16:03:13 +0100 Subject: [PATCH 04/23] Not working --- include/xeus-python/xinterpreter.hpp | 2 +- src/main.cpp | 74 +++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 1382a024..d9f272ca 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -91,7 +91,7 @@ namespace xpyt // is started, m_release_gil_at_startup has to be set to false to prevent // releasing it again in configure_impl(). // - bool m_release_gil_at_startup = true; + bool m_release_gil_at_startup = false; gil_scoped_release_ptr m_release_gil = nullptr; bool m_redirect_output_enabled; diff --git a/src/main.cpp b/src/main.cpp index 10857372..ce3390e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" +#include "xeus-zmq/hook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -46,6 +47,51 @@ namespace py = pybind11; +class py_hook : public xeus::hook_base +{ +public: + py_hook() = default; + + void pre_hook() override + { + std::cout << "pre_handle\n"; + p_acquire = new py::gil_scoped_acquire(); + p_release = new py::gil_scoped_release(); + } + + void post_hook() override + { + std::cout << "post_handle\n"; + if (p_acquire) + { + delete p_release; + p_release = nullptr; + delete p_acquire; + p_acquire = nullptr; + std::cout << "done deleting post\n"; + } + std::cout << "post_handle done\n"; + + } + + void run(std::shared_ptr) override + { + std::cout << "Running\n"; + py::gil_scoped_acquire acquire; + py::exec(R"( + import asyncio + loop = asyncio.get_event_loop() + loop.run_forever() + )"); + } + +private: + py::gil_scoped_acquire* p_acquire = nullptr; + py::gil_scoped_release* p_release = nullptr; +}; + + + int main(int argc, char* argv[]) { @@ -94,8 +140,8 @@ int main(int argc, char* argv[]) uv_loop_t* uv_loop_ptr{ nullptr }; - // { - // py::gil_scoped_acquire acquire; + { + py::gil_scoped_acquire acquire; // Instantiating the loop manually py::exec(R"( @@ -119,7 +165,7 @@ int main(int argc, char* argv[]) uv_loop_ptr = static_cast(raw_ptr); std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; - // } + } if (!uv_loop_ptr) { @@ -166,19 +212,21 @@ int main(int argc, char* argv[]) #ifdef XEUS_PYTHON_PYPI_WARNING std::clog << "WARNING: this instance of xeus-python has been installed from a PyPI wheel.\n" - "We recommend using a ge7yuneral-purpose package manager instead, such as Conda/Mamba.\n" + "We recommend using a general-purpose package manager instead, such as Conda/Mamba.\n" << std::endl; #endif nl::json debugger_config; debugger_config["python"] = executable; + auto hook = std::make_unique(); + std::cout << "Making a server\n"; - auto make_xserver = [loop_ptr](xeus::xcontext& context, + auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(hook)); }; std::cout << "Done with the lambda\n"; @@ -204,7 +252,21 @@ int main(int argc, char* argv[]) " the " + connection_filename + " file." << std::endl; + std::cout << "Starting kernel\n"; + kernel.start(); + + std::cout << "Kernel started\n"; + + py::gil_scoped_acquire acquire; + py::exec(R"( + import asyncio + loop = asyncio.get_event_loop() + loop.run_forever() + )"); + + + std::cout << "Ran the loop\n"; } else { From 6526c653c2878652e4bfc745499ca217b1951034 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 12 Mar 2024 10:05:49 +0100 Subject: [PATCH 05/23] Partially working --- src/main.cpp | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ce3390e9..5b95994c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,45 +54,42 @@ class py_hook : public xeus::hook_base void pre_hook() override { - std::cout << "pre_handle\n"; - p_acquire = new py::gil_scoped_acquire(); - p_release = new py::gil_scoped_release(); + // p_release = new py::gil_scoped_release(); + // p_acquire = new py::gil_scoped_acquire(); + std::cout << "Prehook\n"; } void post_hook() override { - std::cout << "post_handle\n"; - if (p_acquire) - { - delete p_release; - p_release = nullptr; - delete p_acquire; - p_acquire = nullptr; - std::cout << "done deleting post\n"; - } - std::cout << "post_handle done\n"; + // delete p_acquire; + // delete p_release; + // p_acquire = nullptr; + // p_release = nullptr; + std::cout << "Posthook\n"; } void run(std::shared_ptr) override { - std::cout << "Running\n"; + std::cout << "Overriden run\n"; + py::gil_scoped_acquire acquire; + std::cout << "After acquire gil\n"; py::exec(R"( import asyncio loop = asyncio.get_event_loop() + print('got a loop', loop) loop.run_forever() )"); } private: - py::gil_scoped_acquire* p_acquire = nullptr; - py::gil_scoped_release* p_release = nullptr; + py::gil_scoped_acquire* p_acquire{ nullptr }; + py::gil_scoped_release* p_release{ nullptr }; }; - int main(int argc, char* argv[]) { if (xpyt::should_print_version(argc, argv)) @@ -258,15 +255,6 @@ int main(int argc, char* argv[]) std::cout << "Kernel started\n"; - py::gil_scoped_acquire acquire; - py::exec(R"( - import asyncio - loop = asyncio.get_event_loop() - loop.run_forever() - )"); - - - std::cout << "Ran the loop\n"; } else { From f167fdbb78af28b6159402585a932fdd5dcd5fdc Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 12 Mar 2024 11:26:29 +0100 Subject: [PATCH 06/23] Working --- src/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5b95994c..1c5020e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,16 +55,17 @@ class py_hook : public xeus::hook_base void pre_hook() override { // p_release = new py::gil_scoped_release(); - // p_acquire = new py::gil_scoped_acquire(); - std::cout << "Prehook\n"; + if (!p_acquire) + { + std::cout << "Acquiring GIL\n"; + p_acquire = new py::gil_scoped_acquire(); + } } void post_hook() override { - // delete p_acquire; - // delete p_release; - // p_acquire = nullptr; - // p_release = nullptr; + delete p_acquire; + p_acquire = nullptr; std::cout << "Posthook\n"; } @@ -85,7 +86,6 @@ class py_hook : public xeus::hook_base private: py::gil_scoped_acquire* p_acquire{ nullptr }; - py::gil_scoped_release* p_release{ nullptr }; }; From f1290dcc28b8b00a09c88b8b7a2ffe22fdbcec83 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Wed, 13 Mar 2024 19:15:10 +0100 Subject: [PATCH 07/23] Rename xhook --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c5020e3..5ce20a38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" -#include "xeus-zmq/hook_base.hpp" +#include "xeus-zmq/xhook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -47,7 +47,7 @@ namespace py = pybind11; -class py_hook : public xeus::hook_base +class py_hook : public xeus::xhook_base { public: py_hook() = default; From ca0b1fd6df071dc547785a15b68928dfeff50f2d Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 15 Mar 2024 17:26:40 +0100 Subject: [PATCH 08/23] Move hook --- CMakeLists.txt | 2 ++ include/xeus-python/xhook.hpp | 40 +++++++++++++++++++++++++++ src/main.cpp | 48 +++------------------------------ src/xhook.cpp | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 45 deletions(-) create mode 100644 include/xeus-python/xhook.hpp create mode 100644 src/xhook.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f0a771..2b941d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,7 @@ set(XEUS_PYTHON_SRC src/xdebugpy_client.cpp src/xdisplay.cpp src/xdisplay.hpp + src/xhook.cpp src/xinput.cpp src/xinput.hpp src/xinspect.cpp @@ -175,6 +176,7 @@ set(XEUS_PYTHON_HEADERS include/xeus-python/xinterpreter_raw.hpp include/xeus-python/xtraceback.hpp include/xeus-python/xutils.hpp + include/xeus-python/xhook.hpp ) set(XPYTHON_SRC diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp new file mode 100644 index 00000000..dfb7471e --- /dev/null +++ b/include/xeus-python/xhook.hpp @@ -0,0 +1,40 @@ +/*************************************************************************** +* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * +* Wolf Vollprecht * +* Copyright (c) 2018, QuantStack +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XPYT_HOOK_HPP +#define XPYT_HOOK_HPP + +#include "xeus-python/xeus_python_config.hpp" +#include "xeus-zmq/xhook_base.hpp" + +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" + +namespace py = pybind11; + +namespace xpyt +{ + XEUS_PYTHON_API + class hook : public xeus::xhook_base + { + public: + hook() = default; + + void pre_hook() override; + void post_hook() override; + void run(std::shared_ptr loop) override; + + private: + py::gil_scoped_acquire* p_acquire{ nullptr}; + }; + +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 5ce20a38..6382caf0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,52 +44,10 @@ #include "xeus-python/xpaths.hpp" #include "xeus-python/xeus_python_config.hpp" #include "xeus-python/xutils.hpp" +#include "xeus-python/xhook.hpp" namespace py = pybind11; -class py_hook : public xeus::xhook_base -{ -public: - py_hook() = default; - - void pre_hook() override - { - // p_release = new py::gil_scoped_release(); - if (!p_acquire) - { - std::cout << "Acquiring GIL\n"; - p_acquire = new py::gil_scoped_acquire(); - } - } - - void post_hook() override - { - delete p_acquire; - p_acquire = nullptr; - std::cout << "Posthook\n"; - - } - - void run(std::shared_ptr) override - { - std::cout << "Overriden run\n"; - - py::gil_scoped_acquire acquire; - std::cout << "After acquire gil\n"; - py::exec(R"( - import asyncio - loop = asyncio.get_event_loop() - print('got a loop', loop) - loop.run_forever() - )"); - } - -private: - py::gil_scoped_acquire* p_acquire{ nullptr }; -}; - - - int main(int argc, char* argv[]) { if (xpyt::should_print_version(argc, argv)) @@ -216,14 +174,14 @@ int main(int argc, char* argv[]) nl::json debugger_config; debugger_config["python"] = executable; - auto hook = std::make_unique(); + auto py_hook = std::make_unique(); std::cout << "Making a server\n"; auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(hook)); + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); }; std::cout << "Done with the lambda\n"; diff --git a/src/xhook.cpp b/src/xhook.cpp new file mode 100644 index 00000000..402a81d4 --- /dev/null +++ b/src/xhook.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** +* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * +* Wolf Vollprecht * +* Copyright (c) 2018, QuantStack +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef UVW_AS_LIB +#define UVW_AS_LIB +#include +#endif + +#include // REMOVE + +#include "xeus-python/xhook.hpp" + +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" + +namespace py = pybind11; + +namespace xpyt +{ + void hook::pre_hook() + { + if (!p_acquire) + { + std::cout << "Acquiring GIL" << std::endl; + p_acquire = new py::gil_scoped_acquire(); + } + } + + void hook::post_hook() + { + delete p_acquire; + p_acquire = nullptr; + std::cout << "Deleted GIL" << std::endl; + } + + void hook::run(std::shared_ptr /* loop */) + { + std::cout << "Running loop" << std::endl; + py::gil_scoped_acquire acquire; + py::module asyncio = py::module::import("asyncio"); + py::object loop = asyncio.attr("get_event_loop")(); + loop.attr("run_forever")(); + } +} From b94c5461ccf4a85a02ae45592fea1a4f9deee17c Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 18:00:15 +0100 Subject: [PATCH 09/23] Add uvw dependency --- CMakeLists.txt | 8 +++++++- environment-dev.yml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b941d98..0f6a040b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,9 @@ else () endif () endif() +find_library(UVW_LIBRARY uvw) +find_path(UVW_INCLUDE_DIR uvw.hpp) + # Source files # ============ @@ -306,7 +309,10 @@ macro(xpyt_create_target target_name src headers linkage output_name) set(XPYT_XEUS_TARGET xeus-zmq-static) endif () - target_link_libraries(${target_name} PUBLIC ${XPYT_XEUS_TARGET} xtl PRIVATE pybind11::pybind11 pybind11_json) + target_link_libraries(${target_name} + PUBLIC ${XPYT_XEUS_TARGET} xtl ${UVW_LIBRARY} + PRIVATE pybind11::pybind11 pybind11_json + ) if (WIN32 OR CYGWIN) target_link_libraries(${target_name} PRIVATE ${PYTHON_LIBRARIES}) elseif (APPLE) diff --git a/environment-dev.yml b/environment-dev.yml index fb4fb18d..1117f6d9 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,6 +15,7 @@ dependencies: - pybind11_json>=0.2.6,<0.3 - xeus-python-shell>=0.5.0,<0.6 - debugpy>=1.6.5 + - libuvw # Test dependencies - pytest - nbval From e4241b3413690707f17fb19d35b970d92ae89795 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 18:54:46 +0100 Subject: [PATCH 10/23] Ignore pybind11 visibility warning --- include/xeus-python/xhook.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index dfb7471e..7dc2a126 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -11,6 +11,15 @@ #ifndef XPYT_HOOK_HPP #define XPYT_HOOK_HPP +// pybind11 code internally forces hidden visibility on all internal code, but +// if non-hidden (and thus exported) code attempts to include a pybind type +// this warning occurs: +// 'xpyt::hook' declared with greater visibility than the type of its +// field 'xpyt::hook::p_acquire' [-Wattributes] +#ifdef __GNUC__ + #pragma GCC diagnostic ignored "-Wattributes" +#endif + #include "xeus-python/xeus_python_config.hpp" #include "xeus-zmq/xhook_base.hpp" From edad43f2fd403df29e0ffdf4f55d66b23bf8fef5 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 19:30:51 +0100 Subject: [PATCH 11/23] Clean hook --- src/xhook.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/xhook.cpp b/src/xhook.cpp index 402a81d4..5898b673 100644 --- a/src/xhook.cpp +++ b/src/xhook.cpp @@ -13,8 +13,6 @@ #include #endif -#include // REMOVE - #include "xeus-python/xhook.hpp" #include "pybind11/embed.h" @@ -28,7 +26,6 @@ namespace xpyt { if (!p_acquire) { - std::cout << "Acquiring GIL" << std::endl; p_acquire = new py::gil_scoped_acquire(); } } @@ -37,12 +34,10 @@ namespace xpyt { delete p_acquire; p_acquire = nullptr; - std::cout << "Deleted GIL" << std::endl; } void hook::run(std::shared_ptr /* loop */) { - std::cout << "Running loop" << std::endl; py::gil_scoped_acquire acquire; py::module asyncio = py::module::import("asyncio"); py::object loop = asyncio.attr("get_event_loop")(); From 8c685c68545db73bfbaad81f89bb0d9889664678 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 19 Mar 2024 10:32:22 +0100 Subject: [PATCH 12/23] Clean main --- src/main.cpp | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6382caf0..ed7be810 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,39 +98,28 @@ int main(int argc, char* argv[]) { py::gil_scoped_acquire acquire; - // Instantiating the loop manually - py::exec(R"( - import asyncio - import uvloop - from uvloop.loop import libuv_get_loop_t_ptr - - print('Creating uvloop event loop') - loop = uvloop.new_event_loop() - asyncio.set_event_loop(loop) - print('uvloop event loop created') - )"); - - py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr(loop)"); + // Create a uvloop and get pointer to the loop + py::module asyncio = py::module::import("asyncio"); + py::module uvloop = py::module::import("uvloop"); + py::object loop = uvloop.attr("new_event_loop")(); + asyncio.attr("set_event_loop")(loop); + py::object py_loop_ptr = uvloop.attr("loop").attr("libuv_get_loop_t_ptr")(loop); + void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); if (!raw_ptr) { - std::cout << "Got null pointer!\n"; - throw std::runtime_error("Failed to get libuv loop pointer"); + throw std::runtime_error("Failed to get uvloop pointer"); } uv_loop_ptr = static_cast(raw_ptr); - std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; } if (!uv_loop_ptr) { throw std::runtime_error("Failed to get libuv loop pointer"); - std::cout << "This pointer is no good\n"; } auto loop_ptr = uvw::loop::create(uv_loop_ptr); - std::cout << "Got a loop!\n"; - // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; for(auto i = 0; i < argc; ++i) @@ -176,16 +165,12 @@ int main(int argc, char* argv[]) auto py_hook = std::make_unique(); - std::cout << "Making a server\n"; - auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); }; - std::cout << "Done with the lambda\n"; - if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -207,12 +192,7 @@ int main(int argc, char* argv[]) " the " + connection_filename + " file." << std::endl; - std::cout << "Starting kernel\n"; - kernel.start(); - - std::cout << "Kernel started\n"; - } else { From 3de58650d8eb12b48bfc7bd60a6746c009305d8e Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Wed, 17 Apr 2024 10:37:40 +0200 Subject: [PATCH 13/23] Fix hook implementaion --- include/xeus-python/xhook.hpp | 11 +++++++---- src/xhook.cpp | 11 ++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index 7dc2a126..e79725e3 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -34,13 +34,16 @@ namespace xpyt class hook : public xeus::xhook_base { public: - hook() = default; - void pre_hook() override; - void post_hook() override; - void run(std::shared_ptr loop) override; + hook() = default; + virtual ~hook(); private: + + void pre_hook_impl() override; + void post_hook_impl() override; + void run_impl(std::shared_ptr loop) override; + py::gil_scoped_acquire* p_acquire{ nullptr}; }; diff --git a/src/xhook.cpp b/src/xhook.cpp index 5898b673..5fcf2db1 100644 --- a/src/xhook.cpp +++ b/src/xhook.cpp @@ -22,7 +22,12 @@ namespace py = pybind11; namespace xpyt { - void hook::pre_hook() + hook::~hook() + { + delete p_acquire; + } + + void hook::pre_hook_impl() { if (!p_acquire) { @@ -30,13 +35,13 @@ namespace xpyt } } - void hook::post_hook() + void hook::post_hook_impl() { delete p_acquire; p_acquire = nullptr; } - void hook::run(std::shared_ptr /* loop */) + void hook::run_impl(std::shared_ptr /* loop */) { py::gil_scoped_acquire acquire; py::module asyncio = py::module::import("asyncio"); From 44f8a31992f821a74cbae9fdfebd4e0799d5ff6b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:15:46 +0100 Subject: [PATCH 14/23] updates --- CMakeLists.txt | 6 ++++-- include/xeus-python/xhook.hpp | 2 +- src/main.cpp | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ebbd73..65c91971 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,8 @@ else () if (NOT TARGET xeus-zmq AND NOT TARGET xeus-zmq-static) find_package(xeus-zmq ${xeus-zmq_REQUIRED_VERSION} REQUIRED) endif () + + find_package(xeus-uv REQUIRED) endif() find_library(UVW_LIBRARY uvw) @@ -323,7 +325,7 @@ macro(xpyt_create_target target_name src headers linkage output_name) endif () target_link_libraries(${target_name} - PUBLIC ${XPYT_XEUS_TARGET} xtl ${UVW_LIBRARY} + PUBLIC ${XPYT_XEUS_TARGET} ${UVW_LIBRARY} PRIVATE pybind11::pybind11 pybind11_json ) if (WIN32 OR CYGWIN) @@ -379,7 +381,7 @@ endif () if (XPYT_BUILD_XPYTHON_EXECUTABLE) add_executable(xpython ${XPYTHON_SRC}) - target_link_libraries(xpython PRIVATE pybind11::embed) + target_link_libraries(xpython PRIVATE xeus-uv pybind11::embed ) xpyt_set_common_options(xpython) xpyt_set_kernel_options(xpython) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index e79725e3..033edc16 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -21,7 +21,7 @@ #endif #include "xeus-python/xeus_python_config.hpp" -#include "xeus-zmq/xhook_base.hpp" +#include "xeus-uv/xhook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" diff --git a/src/main.cpp b/src/main.cpp index e8e52d2b..fcd4ffce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,11 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" -#include "xeus-zmq/xhook_base.hpp" + + +#include "xeus-uv/xserver_uv.hpp" +#include "xeus-uv/xhook_base.hpp" + #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -143,8 +147,7 @@ int main(int argc, char* argv[]) } delete[] argw; - // Instantiating the Python interpreter - py::scoped_interpreter guard; + std::unique_ptr context = xeus::make_zmq_context(); @@ -178,10 +181,12 @@ int main(int argc, char* argv[]) auto py_hook = std::make_unique(); + + auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); + return xeus::make_xserver_uv(context, config, eh, loop_ptr, std::move(py_hook)); }; if (!connection_filename.empty()) From 8a7cc27d704ff795e508cdae0d07843c38ca3a56 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:17:54 +0100 Subject: [PATCH 15/23] remove mac-13 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9870f650..c79417e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-24.04, macos-13, macos-14] + os: [ubuntu-22.04, ubuntu-24.04, macos-14] build_type: [static_build, shared_build] steps: From 0a8469fcade91373d0264a8bf6d4c51f0a71cd0f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:56:46 +0100 Subject: [PATCH 16/23] movin find uv related code to non-emscripten branch --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65c91971..72053244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,10 +107,11 @@ else () endif () find_package(xeus-uv REQUIRED) + find_library(UVW_LIBRARY uvw) + find_path(UVW_INCLUDE_DIR uvw.hpp) endif() -find_library(UVW_LIBRARY uvw) -find_path(UVW_INCLUDE_DIR uvw.hpp) + # Configuration # ============= From 3f93c9b58c2e0996aed98a1c91502c383c340e32 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 11:15:08 +0100 Subject: [PATCH 17/23] working --- include/xeus-python/xinterpreter.hpp | 14 +++ notebooks/xeus-python.ipynb | 54 ++++++++++-- src/main.cpp | 5 ++ src/xinterpreter.cpp | 125 ++++++++++++++++++--------- 4 files changed, 148 insertions(+), 50 deletions(-) diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 6c38affd..6ffdae81 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -101,6 +101,20 @@ namespace xpyt private: + // helper methods: + void execute_request_impl_sync(send_reply_callback cb, + int execution_counter, + const std::string& code, + xeus::execute_request_config config, + nl::json user_expressions); + + void execute_request_impl_async(send_reply_callback cb, + int execution_counter, + const std::string& code, + xeus::execute_request_config config, + nl::json user_expressions); + + virtual void instanciate_ipython_shell(); virtual bool use_jedi_for_completion() const; }; diff --git a/notebooks/xeus-python.ipynb b/notebooks/xeus-python.ipynb index 12a0b75b..026d828c 100644 --- a/notebooks/xeus-python.ipynb +++ b/notebooks/xeus-python.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -28,18 +28,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7921" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "b = 89\n", "\n", @@ -51,9 +73,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "print" ] @@ -653,15 +686,18 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9 (XPython)", + "display_name": "Python 3.13 (XPython)", "language": "python", "name": "xpython" }, "language_info": { + "codemirror_mode": "{\"name\": \"ipython\", \"version\": 3}", "file_extension": ".py", "mimetype": "text/x-python", "name": "python", - "version": "3.9.1" + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.11" } }, "nbformat": 4, diff --git a/src/main.cpp b/src/main.cpp index fcd4ffce..f1bf3733 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,9 +111,12 @@ int main(int argc, char* argv[]) py::module uvloop = py::module::import("uvloop"); py::object loop = uvloop.attr("new_event_loop")(); asyncio.attr("set_event_loop")(loop); + + std::cout<<"getting uv loop pointer from uvloop"< traceback; + + + + + auto when_done_callback_lambda = [this, cb, config, user_expressions]() { + py::gil_scoped_acquire acquire; + // Placeholder for any actions to perform when execution is done + + + + // Get payload + nl::json payload = this->m_ipython_shell.attr("payload_manager").attr("read_payload")(); + this->m_ipython_shell.attr("payload_manager").attr("clear_payload")(); + + // if(exception_occurred) + // { + // cb(xeus::create_error_reply(ename, evalue, traceback)); + // return; + // } + + if (this->m_ipython_shell.attr("last_error").is_none()) + { + nl::json user_exprs = this->m_ipython_shell.attr("user_expressions")(user_expressions); + cb(xeus::create_successful_reply(payload, user_exprs)); + } + else + { + py::list pyerror = this->m_ipython_shell.attr("last_error"); + + xerror error = extract_error(pyerror); + + if (!config.silent) + { + publish_execution_error(error.m_ename, error.m_evalue, error.m_traceback); + } + + cb(xeus::create_error_reply(error.m_ename, error.m_evalue, error.m_traceback)); + } + }; + std::function when_done_callback = when_done_callback_lambda; + + + try { - m_ipython_shell.attr("run_cell")(code, "store_history"_a=config.store_history, "silent"_a=config.silent); + m_ipython_shell.attr("run_cell_async")(code, when_done_callback, "store_history"_a=config.store_history, "silent"_a=config.silent); } catch(std::runtime_error& e) { @@ -171,34 +219,12 @@ namespace xpyt exception_occurred = true; } - // Get payload - nl::json payload = m_ipython_shell.attr("payload_manager").attr("read_payload")(); - m_ipython_shell.attr("payload_manager").attr("clear_payload")(); - if(exception_occurred) - { - cb(xeus::create_error_reply(ename, evalue, traceback)); - return; - } - if (m_ipython_shell.attr("last_error").is_none()) - { - nl::json user_exprs = m_ipython_shell.attr("user_expressions")(user_expressions); - cb(xeus::create_successful_reply(payload, user_exprs)); - } - else - { - py::list pyerror = m_ipython_shell.attr("last_error"); - xerror error = extract_error(pyerror); - if (!config.silent) - { - publish_execution_error(error.m_ename, error.m_evalue, error.m_traceback); - } - cb(xeus::create_error_reply(error.m_ename, error.m_evalue, error.m_traceback)); - } + } nl::json interpreter::complete_request_impl( @@ -266,8 +292,7 @@ namespace xpyt } nl::json interpreter::kernel_info_request_impl() - { - + { /* The jupyter-console banner for xeus-python is the following: __ _____ _ _ ___ \ \/ / _ \ | | / __| @@ -300,21 +325,39 @@ namespace xpyt {"url", "https://xeus-python.readthedocs.io"} }); - return xeus::create_info_reply( - "5.3", // protocol_version - "xeus-python", // implementation - XPYT_VERSION, // implementation_version - "python", // language_name - PY_VERSION, // language_version - "text/x-python", // language_mimetype - ".py", // language_file_extension - "ipython" + std::to_string(PY_MAJOR_VERSION), // pygments_lexer - R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}", // language_codemirror_mode - "python", // language_nbconvert_exporter - banner, // banner - (PY_MAJOR_VERSION != 3) || (PY_MINOR_VERSION != 13), // debugger - help_links // help_links - ); + // return xeus::create_info_reply( + // "5.3", // protocol_version + // "xeus-python", // implementation + // XPYT_VERSION, // implementation_version + // "python", // language_name + // PY_VERSION, // language_version + // "text/x-python", // language_mimetype + // ".py", // language_file_extension + // "ipython" + std::to_string(PY_MAJOR_VERSION), // pygments_lexer + // R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}", // language_codemirror_mode + // "python", // language_nbconvert_exporter + // banner, // banner + // (PY_MAJOR_VERSION != 3) || (PY_MINOR_VERSION != 13), // debugger + // help_links // help_links + // ); + + nl::json kernel_res; + kernel_res["status"] = "ok"; + kernel_res["protocol_version"] = "5.3"; + kernel_res["implementation"] = "xeus-python"; + kernel_res["implementation_version"] = XPYT_VERSION; + kernel_res["language_info"]["name"] = "python"; + kernel_res["language_info"]["version"] = PY_VERSION; + kernel_res["language_info"]["mimetype"] = "text/x-python"; + kernel_res["language_info"]["file_extension"] = ".py"; + kernel_res["language_info"]["pygments_lexer"] = "ipython" + std::to_string(PY_MAJOR_VERSION); + //kernel_res["language_info"]["codemirror_mode"] = R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}"; + kernel_res["language_info"]["nbconvert_exporter"] = "python"; + kernel_res["banner"] = banner; + kernel_res["debugger"] = false; + kernel_res["help_links"] = help_links; + return kernel_res; + } void interpreter::shutdown_request_impl() From 9a3468be7e19d2c479e5758a873cde6d8e851577 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:27:35 +0100 Subject: [PATCH 18/23] libuv --- .github/workflows/deploy-github-page.yml | 13 ++++++++++++- environment-wasm-host.yml | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 4f60b9f0..18810490 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -47,6 +47,12 @@ jobs: set -eux + + URL=https://github.com/DerThorsten/xeus-python-shell/archive/refs/heads/libuv.zip + curl -L $URL -o xeus-python-shell.zip + unzip xeus-python-shell.zip + + export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-wasm-host echo "PREFIX=$PREFIX" >> $GITHUB_ENV @@ -60,13 +66,18 @@ jobs: emmake make -j${{ env.ncpus }} install + + + - name: Jupyter Lite integration shell: bash -l {0} run: | jupyter lite build \ --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ - --output-dir dist + --output-dir dist \ + --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + - name: Upload artifact uses: actions/upload-pages-artifact@v4 diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 72e89111..0c3a1034 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -12,9 +12,9 @@ dependencies: - numpy - xeus-lite - xeus - - xeus-python-shell>=0.6.3 - pyjs >=2,<3 - libpython - zstd - openssl - xz + # - xeus-python-shell>=0.6.3 From 9dd02a4661c0f457a9d5e941a3ad083896a91d6d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:30:11 +0100 Subject: [PATCH 19/23] libuv --- .github/workflows/deploy-github-page.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 18810490..f68b7d83 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -49,8 +49,8 @@ jobs: URL=https://github.com/DerThorsten/xeus-python-shell/archive/refs/heads/libuv.zip - curl -L $URL -o xeus-python-shell.zip - unzip xeus-python-shell.zip + curl -L $URL -o xeus-python-shell-libuv.zip + unzip xeus-python-shell-libuv.zip export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-wasm-host @@ -76,7 +76,7 @@ jobs: --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" - name: Upload artifact From 565eb44bb520ae2ae139a60ecbb5b01098306f71 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:35:40 +0100 Subject: [PATCH 20/23] path --- .github/workflows/deploy-github-page.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index f68b7d83..36e30f5e 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -76,7 +76,7 @@ jobs: --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=/home/runner/work/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" - name: Upload artifact From 8924b65e6a798bce5eb632a04f6c595c54409b32 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:44:38 +0100 Subject: [PATCH 21/23] path --- .github/workflows/deploy-github-page.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 36e30f5e..6929951a 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -33,7 +33,7 @@ jobs: environment-file: environment-wasm-build.yml init-shell: bash environment-name: xeus-python-wasm-build - + - name: Set ncpus run: echo "ncpus=$(nproc --all)" >> $GITHUB_ENV @@ -72,11 +72,12 @@ jobs: - name: Jupyter Lite integration shell: bash -l {0} run: | + THIS_DIR=$(pwd) jupyter lite build \ --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/work/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=$THIS_DIR/xeus-python-shell-libuv/xeus_python_shell/:/lib/python3.13/site-packages/xeus_python_shell/ - name: Upload artifact From 1d5b86317c1a0dfa932100d7af8397ee93bca386 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:50:48 +0100 Subject: [PATCH 22/23] path --- environment-wasm-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/environment-wasm-build.yml b/environment-wasm-build.yml index 617bf918..59cec0e7 100644 --- a/environment-wasm-build.yml +++ b/environment-wasm-build.yml @@ -13,3 +13,5 @@ dependencies: - jupyterlite-core >0.6 - jupyter_server - jupyterlite-xeus + - # widgets + - ipywidgets \ No newline at end of file From 1b691293a5968dce1cbdcbab8c9c5933226cd734 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 14:12:40 +0100 Subject: [PATCH 23/23] widgets --- environment-wasm-host.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 0c3a1034..9004a4a5 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -17,4 +17,6 @@ dependencies: - zstd - openssl - xz + - ipywidgets # - xeus-python-shell>=0.6.3 +