Skip to content

Commit

Permalink
Merge pull request #35 from SandrineP/upgrade_xeus
Browse files Browse the repository at this point in the history
Upgrade xeus to xeus 5
  • Loading branch information
JohanMabille authored Dec 16, 2024
2 parents ae659ec + f58cb0a commit 3401f20
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 47 deletions.
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ configure_file (
# ============

# Be sure to use recent versions
set(xeus_REQUIRED_VERSION 2.1.0)
set(xeus-zmq_REQUIRED_VERSION 3.0.0)
set(cppzmq_REQUIRED_VERSION 4.3.0)

find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
find_package(xeus-zmq ${xeus-zmq_REQUIRED_VERSION} REQUIRED)
find_package(cppzmq ${cppzmq_REQUIRED_VERSION} REQUIRED)

# Flags
Expand All @@ -54,15 +54,16 @@ include(CheckCXXCompilerFlag)

set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)

if (HAS_CPP14_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(FATAL_ERROR "Unsupported compiler -- xeus requires C++14 support!")
endif()
endif()
#if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
#
# if (HAS_CPP14_FLAG)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# else()
# message(FATAL_ERROR "Unsupported compiler -- xeus requires C++14 support!")
# endif()
#endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# Target and link
# ===============
Expand All @@ -82,10 +83,11 @@ set(XEUS_CALC_HEADERS

# xeus-calc is the target for the library
add_library(xeus-calc SHARED ${XEUS_CALC_SRC} ${XEUS_CALC_HEADERS})

target_compile_features(xeus-calc PRIVATE cxx_std_17)

# xcalc is the target for the kernel executable
add_executable(xcalc src/main.cpp)
target_compile_features(xcalc PRIVATE cxx_std_17)
set_target_properties(xcalc PROPERTIES ENABLE_EXPORTS 1)
target_link_libraries(xcalc PRIVATE xeus-calc)
target_compile_definitions(xcalc PRIVATE XEUS_CALC_HOME="${XCALC_PREFIX}")
Expand Down Expand Up @@ -113,7 +115,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()

target_link_libraries(xeus-calc PUBLIC xeus)
target_link_libraries(xeus-calc PUBLIC xeus-zmq)


set_target_properties(xcalc PROPERTIES
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Calculator as a Jupyter Kernel implemented with Xeus

## Usage
## Usage

Launch the Jupyter notebook with `jupyter notebook` or Jupyter lab with `jupyter lab` and launch a new notebook by selecting the **xeus-calc** kernel.

Expand All @@ -19,7 +19,7 @@ Launch the Jupyter notebook with `jupyter notebook` or Jupyter lab with `jupyter
To ensure that the installation works, it is preferable to install `xeus` in a fresh mamba/conda environment.

```bash
mamba create -n xeus-calc-env -c conda-forge xtl nlohmann_json cppzmq xeus
mamba create -n xeus-calc-env -c conda-forge -f environment-dev.yml
```

Once you have installed ` xeus ` ,the ` xeus-calc ` project is quite easy to install, you have to clone the repository, and run the following command lines :
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
# Build dependencies
- cmake
# Host dependencies
- xeus=2.1.0
- xeus-zmq=3.1.0
- nlohmann_json
- cppzmq
- xtl=0.7.3
11 changes: 0 additions & 11 deletions environment.yml

This file was deleted.

13 changes: 7 additions & 6 deletions include/xeus-calc/xeus_calc_interpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "xeus_calc_config.hpp"

#include "xeus/xrequest_context.hpp"

namespace nl = nlohmann;

namespace xeus_calc
Expand All @@ -32,12 +34,11 @@ namespace xeus_calc

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(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
13 changes: 7 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "xeus/xeus_context.hpp"
#include "xeus/xkernel.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus/xserver_zmq.hpp"
#include "xeus/xserver.hpp"

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

#include "xeus-calc/xeus_calc_interpreter.hpp"

Expand All @@ -23,20 +26,18 @@ int main(int argc, char* argv[])
xeus::xconfiguration config = xeus::load_configuration(file_name);

// Create context
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();

// Create interpreter instance
using interpreter_ptr = std::unique_ptr<xeus_calc::interpreter>;
interpreter_ptr interpreter = std::make_unique<xeus_calc::interpreter>();
interpreter_ptr interpreter = interpreter_ptr(new xeus_calc::interpreter());

// Create kernel instance and start it
xeus::xkernel kernel(config,
xeus::get_user_name(),
std::move(context),
std::move(interpreter),
xeus::make_xserver_zmq);
xeus::make_xserver_shell_main);
kernel.start();

return 0;
Expand Down
15 changes: 7 additions & 8 deletions src/xeus_calc_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ namespace xeus_calc
return evaluation.back();
}

nl::json interpreter::execute_request_impl(int execution_counter,
const std::string& code,
bool /*silent*/,
bool /*store_history*/,
nl::json /*user_expressions*/,
bool /*allow_stdin*/)
void interpreter::execute_request_impl(send_reply_callback cb,
int execution_counter,
const std::string& code,
xeus::execute_request_config config,
nl::json user_expression)
{
// You can use the C-API of your target language for executing the code,
// e.g. `PyRun_String` for the Python C-API
Expand All @@ -254,14 +253,14 @@ namespace xeus_calc
jresult["status"] = "ok";
jresult["payload"] = nl::json::array();
jresult["user_expressions"] = nl::json::object();
return jresult;
cb(jresult);
}
catch (const std::runtime_error& err)
{
nl::json jresult;
publish_stream("stderr", err.what());
jresult["status"] = "error";
return jresult;
cb(jresult);
}
// You can also use this method for publishing errors to the client, if the code
// failed to execute
Expand Down

0 comments on commit 3401f20

Please sign in to comment.