diff --git a/CMakeLists.txt b/CMakeLists.txt index 8933e18b..251379af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,9 @@ endif() # Dependencies # ============ -set(xtl_REQUIRED_VERSION 0.7.0) -set(xeus_REQUIRED_VERSION 3.2.0) -set(xeus_zmq_REQUIRED_VERSION 1.0.2) +set(xeus_REQUIRED_VERSION 5.0.0) +set(xeus_zmq_REQUIRED_VERSION 3.0.0) -if (NOT TARGET xtl) - find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED) -endif () if (NOT TARGET xeus AND NOT TARGET xeus-static) find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED) if (xeus_FOUND) @@ -304,7 +300,7 @@ macro(xeus_cpp_create_target target_name linkage output_name) set(XEUS_CPP_XEUS_TARGET xeus-static) endif () - target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse xtl) + target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse) if (WIN32 OR CYGWIN) # diff --git a/README.md b/README.md index 8adcee9c..a47adc3e 100644 --- a/README.md +++ b/README.md @@ -128,20 +128,25 @@ http://xeus-cpp.readthedocs.io `xeus-cpp` depends on + - [xeus-zmq](https://github.com/jupyter-xeus/xeus-zmq) -- [xtl](https://github.com/xtensor-stack/xtl) - [nlohmann_json](https://github.com/nlohmann/json) - [cppzmq](https://github.com/zeromq/cppzmq) -- [clang](https://github.com/llvm/llvm-project/) - [argparse](https://github.com/p-ranav/argparse) +- [CppInterOp](https://github.com/compiler-research/CppInterOp) + +| `xeus-cpp` | `xeus-zmq` | `CppInterOp` | `pugixml` | `cppzmq` | `cpp-argparse`| `nlohmann_json` | +|------------|-----------------|--------------|-----------|----------|---------------|-----------------| +| main | >=3.0.0,<4.0.0 | >=1.3.0 | ~1.8.1 | ~4.3.0 | <3.1 | >=3.11.3,<4.0 | + +Versions prior to `main` have an additional dependency on [xtl](https://github.com/xtensor-stack/xtl) & [clang](https://github.com/llvm/llvm-project/). -| `xeus-cpp` | `xeus-zmq` | `xtl` | `CppInterOp` | `clang` | `pugixml` | `cppzmq` | `cpp-argparse`| `nlohmann_json` | -|------------|-----------------|-----------------|--------------|-----------|-----------|----------|---------------|-----------------| -| main | >=1.0.2,<2.0.0 | >=0.7.7,<0.8.0 | >=1.3.0 | | ~1.8.1 | ~4.3.0 | <3.1 | >=3.11.2,<4.0 | -| 0.4.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | -| 0.3.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | -| 0.2.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | -| 0.1.0 | >=1.0.0,<2.0.0 | >=0.7.0,<0.8.0 | | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | +| `xeus-cpp` | `xeus-zmq` | `xtl` | `clang` | `pugixml` | `cppzmq` | `cpp-argparse`| `nlohmann_json` | +|------------|-----------------|-----------------|-----------|-----------|----------|---------------|-----------------| +| 0.4.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | +| 0.3.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | +| 0.2.0 | >=1.0.0,<2.0.0 | >=0.7.7,<0.8.0 | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | +| 0.1.0 | >=1.0.0,<2.0.0 | >=0.7.0,<0.8.0 | >=16,<17 | ~1.8.1 | ~4.3.0 | ~2.9 | >=3.6.1,<4.0 | ## Contributing diff --git a/environment-dev.yml b/environment-dev.yml index 28348596..1fa77ce8 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -7,17 +7,17 @@ dependencies: - cmake - cxx-compiler # Host dependencies - - xeus-zmq >=1.0.2,<2.0 - - nlohmann_json=3.11.2 + - xeus>=5.0.0 + - xeus-zmq>=3.0,<4.0 + - nlohmann_json=3.11.3 - cppzmq - - xtl - CppInterOp>=1.3.0 - pugixml - cpp-argparse <3.1 - zlib # Test dependencies - pytest - - jupyter_kernel_test>=0.4.3 + - jupyter_kernel_test>=0.5,<0.6 - nbval - pytest-rerunfailures - doctest \ No newline at end of file diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 37304638..99db9689 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -4,9 +4,8 @@ channels: - https://repo.mamba.pm/conda-forge dependencies: - nlohmann_json - - xeus-lite <2.0 - - xeus >=3.2.0,<4.0 - - xtl >=0.7,<0.8 + - xeus-lite + - xeus - CppInterOp>=1.3.0 - cpp-argparse - pugixml diff --git a/include/xeus-cpp/xinterpreter.hpp b/include/xeus-cpp/xinterpreter.hpp index a56abe79..25eeb049 100644 --- a/include/xeus-cpp/xinterpreter.hpp +++ b/include/xeus-cpp/xinterpreter.hpp @@ -44,13 +44,12 @@ namespace xcpp void configure_impl() override; - nl::json execute_request_impl( + void execute_request_impl( + send_reply_callback cb, int execution_counter, const std::string& code, - bool silent, - bool store_history, - nl::json user_expressions, - bool allow_stdin + xeus::execute_request_config config, + nl::json user_expressions ) override; nl::json complete_request_impl(const std::string& code, int cursor_pos) override; diff --git a/notebooks/xeus-cpp.ipynb b/notebooks/xeus-cpp.ipynb index 4c30b02c..c75f1d1c 100644 --- a/notebooks/xeus-cpp.ipynb +++ b/notebooks/xeus-cpp.ipynb @@ -479,7 +479,7 @@ "\n", "#include \"nlohmann/json.hpp\"\n", "\n", - "#include \"xtl/xbase64.hpp\"\n", + "#include \"xeus/xbase64.hpp\"\n", "\n", "namespace nl = nlohmann;\n", "\n", @@ -499,7 +499,7 @@ " nl::json mime_bundle_repr(const image& i)\n", " {\n", " auto bundle = nl::json::object();\n", - " bundle[\"image/png\"] = xtl::base64encode(i.m_buffer.str());\n", + " bundle[\"image/png\"] = xeus::base64encode(i.m_buffer.str());\n", " return bundle;\n", " }\n", "}" @@ -579,7 +579,7 @@ "\n", "#include \"nlohmann/json.hpp\"\n", "\n", - "#include \"xtl/xbase64.hpp\"\n", + "#include \"xeus/xbase64.hpp\"\n", "\n", "namespace nl = nlohmann;\n", "\n", @@ -601,7 +601,7 @@ " auto bundle = nl::json::object();\n", " bundle[\"text/html\"] =\n", " std::string(\"\";\n", " return bundle;\n", " }\n", diff --git a/src/main.cpp b/src/main.cpp index 83f6f73f..9ec1b248 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include #include +#include "xeus-zmq/xzmq_context.hpp" #include #include "xeus-cpp/xeus_cpp_config.hpp" @@ -61,18 +62,20 @@ int main(int argc, char* argv[]) interpreter_ptr interpreter = xcpp::build_interpreter(argc, argv); - auto context = xeus::make_context(); + // auto context = xeus::make_context(); + std::unique_ptr context = xeus::make_zmq_context(); if (!file_name.empty()) { xeus::xconfiguration config = xeus::load_configuration(file_name); + std::clog << "Instantiating kernel" << std::endl; xeus::xkernel kernel( config, xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_zmq, + xeus::make_xserver_default, xeus::make_in_memory_history_manager(), xeus::make_console_logger( xeus::xlogger::msg_type, @@ -94,7 +97,7 @@ int main(int argc, char* argv[]) xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_zmq, + xeus::make_xserver_default, xeus::make_in_memory_history_manager(), xeus::make_console_logger( xeus::xlogger::msg_type, @@ -102,6 +105,7 @@ int main(int argc, char* argv[]) ) ); + std::cout << "Getting config" << std::endl; const auto& config = kernel.get_config(); std::clog << "Starting xcpp kernel...\n\n" "If you want to connect to this kernel from an other client, just copy" diff --git a/src/xinspect.hpp b/src/xinspect.hpp index 17c0cdcc..b83fba95 100644 --- a/src/xinspect.hpp +++ b/src/xinspect.hpp @@ -15,8 +15,6 @@ #include -#include - #include "xeus-cpp/xbuffer.hpp" #include "xeus-cpp/xpreamble.hpp" diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 686e7652..e7dd2963 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include "xeus/xsystem.hpp" #include @@ -127,19 +127,18 @@ __get_cxx_version () restore_output(); } - nl::json interpreter::execute_request_impl( - int /*execution_counter*/, + void interpreter::execute_request_impl( + send_reply_callback cb, + int /*execution_count*/, const std::string& code, - bool silent, - bool /*store_history*/, - nl::json /*user_expressions*/, - bool allow_stdin + xeus::execute_request_config config, + nl::json /*user_expressions*/ ) { nl::json kernel_res; - auto input_guard = input_redirection(allow_stdin); + auto input_guard = input_redirection(config.allow_stdin); // Check for magics for (auto& pre : preamble_manager.preamble) @@ -147,7 +146,8 @@ __get_cxx_version () if (pre.second.is_match(code)) { pre.second.apply(code, kernel_res); - return kernel_res; + cb(kernel_res); + return; } } @@ -162,7 +162,7 @@ __get_cxx_version () auto cout_strbuf = std::cout.rdbuf(); auto cerr_strbuf = std::cerr.rdbuf(); - if (silent) + if (config.silent) { auto null = xnull(); std::cout.rdbuf(&null); @@ -202,7 +202,7 @@ __get_cxx_version () std::cerr << std::flush; // Reset non-silent output buffers - if (silent) + if (config.silent) { std::cout.rdbuf(cout_strbuf); std::cerr.rdbuf(cerr_strbuf); @@ -221,7 +221,7 @@ __get_cxx_version () ename = " "; } std::vector traceback({ename + evalue}); - if (!silent) + if (!config.silent) { publish_execution_error(ename, evalue, traceback); } @@ -237,7 +237,7 @@ __get_cxx_version () /* // Publish a mime bundle for the last return value if // the semicolon was omitted. - if (!silent && output.hasValue() && trim(code).back() != ';') + if (!config.silent && output.hasValue() && trim(code).back() != ';') { nl::json pub_data = mime_repr(output); publish_execution_result(execution_counter, std::move(pub_data), nl::json::object()); @@ -248,7 +248,7 @@ __get_cxx_version () kernel_res["payload"] = nl::json::array(); kernel_res["user_expressions"] = nl::json::object(); } - return kernel_res; + cb(kernel_res); } nl::json interpreter::complete_request_impl(const std::string& code, int cursor_pos) @@ -387,7 +387,7 @@ __get_cxx_version () void interpreter::init_includes() { - Cpp::AddIncludePath((xtl::prefix_path() + "/include/").c_str()); + Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str()); } void interpreter::init_preamble() diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index df3698db..26d5484e 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -6,6 +6,8 @@ * The full license is in the file LICENSE, distributed with this software. ****************************************************************************/ +#include + #include "doctest/doctest.h" #include "xeus-cpp/xinterpreter.hpp" #include "xeus-cpp/xholder.hpp" @@ -67,13 +69,28 @@ TEST_SUITE("execute_request") xcpp::interpreter interpreter((int)Args.size(), Args.data()); std::string code = "#include "; nl::json user_expressions = nl::json::object(); - nl::json result = interpreter.execute_request( + xeus::execute_request_config config; + config.silent = false; + config.store_history = false; + config.allow_stdin = false; + nl::json header = nl::json::object(); + xeus::xrequest_context::guid_list id = {}; + xeus::xrequest_context context(header, id); + + std::promise promise; + std::future future = promise.get_future(); + auto callback = [&promise](nl::json result) { + promise.set_value(result); + }; + + interpreter.execute_request( + std::move(context), + std::move(callback), code, - /*silent=*/false, - /*store_history=*/false, - user_expressions, - /*allow_stdin=*/false + std::move(config), + user_expressions ); + nl::json result = future.get(); REQUIRE(result["status"] == "ok"); } @@ -85,15 +102,28 @@ TEST_SUITE("execute_request") std::string code = "?std::vector"; std::string inspect_result = "https://en.cppreference.com/w/cpp/container/vector"; nl::json user_expressions = nl::json::object(); + xeus::execute_request_config config; + config.silent = false; + config.store_history = false; + config.allow_stdin = false; + nl::json header = nl::json::object(); + xeus::xrequest_context::guid_list id = {}; + xeus::xrequest_context context(header, id); + + std::promise promise; + std::future future = promise.get_future(); + auto callback = [&promise](nl::json result) { + promise.set_value(result); + }; - nl::json result = interpreter.execute_request( - code, - false, - false, - user_expressions, - false + interpreter.execute_request( + std::move(context), + std::move(callback), + code, + std::move(config), + user_expressions ); - + nl::json result = future.get(); REQUIRE(result["payload"][0]["data"]["text/plain"] == inspect_result); REQUIRE(result["user_expressions"] == nl::json::object()); REQUIRE(result["found"] == true); @@ -107,15 +137,28 @@ TEST_SUITE("execute_request") std::string code = "int x = ;"; nl::json user_expressions = nl::json::object(); + xeus::execute_request_config config; + config.silent = false; + config.store_history = false; + config.allow_stdin = false; + nl::json header = nl::json::object(); + xeus::xrequest_context::guid_list id = {}; + xeus::xrequest_context context(header, id); + + std::promise promise; + std::future future = promise.get_future(); + auto callback = [&promise](nl::json result) { + promise.set_value(result); + }; - nl::json result = interpreter.execute_request( - code, - false, - false, - user_expressions, - false + interpreter.execute_request( + std::move(context), + std::move(callback), + code, + std::move(config), + user_expressions ); - + nl::json result = future.get(); REQUIRE(result["status"] == "error"); } } @@ -745,14 +788,36 @@ TEST_SUITE("complete_request") { std::vector Args = {/*"-v", "resource-dir", "....."*/}; xcpp::interpreter interpreter((int)Args.size(), Args.data()); + std::string code1 = "#include "; + nl::json user_expressions = nl::json::object(); + xeus::execute_request_config config; + config.silent = false; + config.store_history = false; + config.allow_stdin = false; + nl::json header = nl::json::object(); + xeus::xrequest_context::guid_list id = {}; + xeus::xrequest_context context(header, id); + + std::promise promise; + std::future future = promise.get_future(); + auto callback = [&promise](nl::json result) { + promise.set_value(result); + }; - nl::json execute = interpreter.execute_request("#include ", false, false, nl::json::object(), false); + interpreter.execute_request( + std::move(context), + std::move(callback), + code1, + std::move(config), + user_expressions + ); + nl::json execute = future.get(); REQUIRE(execute["status"] == "ok"); - std::string code = "st"; + std::string code2 = "st"; int cursor_pos = 2; - nl::json result = interpreter.complete_request(code, cursor_pos); + nl::json result = interpreter.complete_request(code2, cursor_pos); REQUIRE(result["cursor_start"] == 0); REQUIRE(result["cursor_end"] == 2); diff --git a/test/test_xcpp_kernel.py b/test/test_xcpp_kernel.py index f6c470a9..8f45b7de 100644 --- a/test/test_xcpp_kernel.py +++ b/test/test_xcpp_kernel.py @@ -110,7 +110,7 @@ class XCppTests(jupyter_kernel_test.KernelTests): #include #include #include "nlohmann/json.hpp" - #include "xtl/xbase64.hpp" + #include "xeus/xbase64.hpp" namespace im { struct image { inline image(const std::string& filename) { @@ -121,7 +121,7 @@ class XCppTests(jupyter_kernel_test.KernelTests): }; nlohmann::json mime_bundle_repr(const image& i) { auto bundle = nlohmann::json::object(); - bundle["image/png"] = xtl::base64encode(i.m_buffer.str()); + bundle["image/png"] = xeus::base64encode(i.m_buffer.str()); return bundle; } } diff --git a/xeus-cppConfig.cmake.in b/xeus-cppConfig.cmake.in index 2c3c52f3..be50a911 100644 --- a/xeus-cppConfig.cmake.in +++ b/xeus-cppConfig.cmake.in @@ -21,7 +21,6 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR};${CMAKE_MODULE_PATH}") @XEUS_CPP_CONFIG_CODE@ include(CMakeFindDependencyMacro) -find_dependency(xtl @xtl_REQUIRED_VERSION@) find_dependency(xeus-zmq @xeus-zmq_REQUIRED_VERSION@) find_dependency(cppzmq @cppzmq_REQUIRED_VERSION@)