Skip to content

Commit e701039

Browse files
Merge pull request #16 from anutosh491/update
Update to xeus 5
2 parents ac90e73 + aada042 commit e701039

9 files changed

+69
-103
lines changed

.github/workflows/main.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ubuntu-20.04, ubuntu-22.04, macos-11, macos-12]
22+
os: [ubuntu-20.04, ubuntu-22.04, macos-12, macos-13]
2323

2424
steps:
2525
- uses: actions/checkout@v4
2626

27-
- name: Get number of CPU cores
28-
uses: SimenB/github-actions-cpu-cores@v1
29-
3027
- name: Install micromamba
3128
uses: mamba-org/setup-micromamba@v1
3229
with:
@@ -46,7 +43,7 @@ jobs:
4643
working-directory: build
4744

4845
- name: Install
49-
run: make -j ${{ steps.cpu-cores.outputs.count }} install
46+
run: make -j ${{ runner.os == 'macOS' && 3 || 4 }} install
5047
working-directory: build
5148

5249
- name: Test

CMakeLists.txt

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#The full license is in the file LICENSE, distributed with this software.
77
#############################################################################
88

9-
cmake_minimum_required(VERSION 3.4.3)
9+
cmake_minimum_required(VERSION 3.24)
1010
project(xeus-nelson)
1111

1212
set(XEUS_NELSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
@@ -62,12 +62,9 @@ endif ()
6262
# Dependencies
6363
# ============
6464

65-
set(xtl_REQUIRED_VERSION 0.7.0)
66-
set(xeus_REQUIRED_VERSION 3.2.0)
65+
set(xeus_REQUIRED_VERSION 5.0.0)
66+
set(xeus_zmq_REQUIRED_VERSION 3.0.0)
6767

68-
if (NOT TARGET xtl)
69-
find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED)
70-
endif ()
7168
if (NOT TARGET xeus AND NOT TARGET xeus-static)
7269
find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
7370
endif ()
@@ -185,7 +182,6 @@ macro(xnelson_create_target target_name linkage output_name)
185182
${target_name}
186183
PUBLIC
187184
${XEUS_NELSON_XEUS_TARGET}
188-
xtl
189185
nlsCore
190186
nlsEngine
191187
nlsText_completion
@@ -233,7 +229,7 @@ endif ()
233229
# =======
234230

235231
if (XEUS_NELSON_BUILD_EXECUTABLE)
236-
find_package(xeus-zmq 1.0.2 REQUIRED)
232+
find_package(xeus-zmq 3.0.0 REQUIRED)
237233
add_executable(xnelson ${XEUS_NELSON_MAIN_SRC})
238234
xnelson_set_common_options(xnelson)
239235
xnelson_set_kernel_options(xnelson)

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mamba install`xeus-nelson` notebook -c conda-forge
3636
Or you can install it from the sources, you will first need to install dependencies
3737

3838
```bash
39-
mamba install cmake cxx-compiler xeus-zmq nlohmann_json cppzmq xtl nelson-core jupyterlab -c conda-forge
39+
mamba install cmake cxx-compiler xeus-zmq nlohmann_json nelson-core jupyterlab -c conda-forge
4040
```
4141

4242
Then you can compile the sources (replace `$CONDA_PREFIX` with a custom installation
@@ -64,11 +64,20 @@ http://xeus-nelson.readthedocs.io
6464
`xeus-nelson` depends on
6565

6666
- [xeus-zmq](https://github.com/jupyter-xeus/xeus-zmq)
67-
- [xtl](https://github.com/xtensor-stack/xtl)
6867
- [nlohmann_json](https://github.com/nlohmann/json)
69-
- [cppzmq](https://github.com/zeromq/cppzmq)
7068
- [nelson-core](https://github.com/Nelson-numerical-software/nelson-minimalist-core)
7169

70+
| `xeus-nelson` | `xeus-zmq` | `nlohmann_json` | `nelson-core` |
71+
|---------------|----------------|-----------------|----------------|
72+
| main | >=3.0,<4.0 | >=3.11.3 | >=0.3,<0.4 |
73+
| 0.5.x | >=3.0,<4.0 | >=3.11.3 | >=0.3,<0.4 |
74+
75+
Prior vo version 0.2, `xeus-nelson` was also depending on [xtl](https://github.com/xtensor-stack/xtl) & [cppzmq](https://github.com/zeromq/cppzmq):
76+
77+
| `xeus-nelson` | `xeus-zmq` | `xtl` | `cppzmq` | `nlohmann_json` | `nelson-core` |
78+
|---------------|------------------|-----------------|----------|-----------------|----------------|
79+
| 0.4.x | >=1.0.0,<2.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.11.2 | >=0.3,<0.4 |
80+
7281
## Contributing
7382

7483
See [CONTRIBUTING.md](./CONTRIBUTING.md) to know how to contribute and set up a

environment-dev.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ dependencies:
77
- ninja
88
- cxx-compiler
99
# Host dependencies
10-
- xeus-zmq >=1.3.0,<2.0
11-
- nlohmann_json
12-
- cppzmq
13-
- xtl
10+
- xeus>=5.0.0
11+
- xeus-zmq>=3.0,<4.0
12+
- nlohmann_json=3.11.3
1413
- nelson-core >=0.3,<0.4
1514
# Test dependencies
1615
- pytest
17-
- jupyter_kernel_test>=0.4.3
16+
- jupyter_kernel_test>=0.5,<0.6
1817
- nbval
1918
- pytest-rerunfailures

environment-wasm-host.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ dependencies:
66
- nelson >=0.3,<0.4
77
- nlohmann_json
88
- xeus-lite
9-
- xeus >=3.2.0,<4.0
10-
- xtl >=0.7,<0.8
9+
- xeus

include/xeus-nelson/xinterpreter.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ namespace xeus_nelson
5353

5454
void configure_impl() override;
5555

56-
nl::json execute_request_impl(int execution_counter,
57-
const std::string& code,
58-
bool silent,
59-
bool store_history,
60-
nl::json user_expressions,
61-
bool allow_stdin) override;
56+
void execute_request_impl(
57+
send_reply_callback cb,
58+
int execution_counter,
59+
const std::string& code,
60+
xeus::execute_request_config config,
61+
nl::json user_expressions
62+
) override;
6263

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

src/main.cpp

+23-57
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* The full license is in the file LICENSE, distributed with this software.
77
****************************************************************************/
88

9-
10-
119
#include <cstdlib>
1210
#include <iostream>
1311
#include <string>
@@ -23,13 +21,14 @@
2321

2422
#include "xeus/xkernel.hpp"
2523
#include "xeus/xkernel_configuration.hpp"
26-
#include "xeus-zmq/xserver_zmq.hpp"
24+
#include <xeus/xhelper.hpp>
2725

26+
#include "xeus-zmq/xserver_zmq.hpp"
27+
#include "xeus-zmq/xzmq_context.hpp"
2828

2929
#include "xeus-nelson/xinterpreter.hpp"
3030
#include "xeus-nelson/xeus_nelson_config.hpp"
3131

32-
3332
#ifdef __GNUC__
3433
void handler(int sig)
3534
{
@@ -45,42 +44,19 @@ void handler(int sig)
4544
}
4645
#endif
4746

48-
bool should_print_version(int argc, char* argv[])
47+
std::unique_ptr<xeus::xlogger> make_file_logger(xeus::xlogger::level log_level)
4948
{
50-
for (int i = 0; i < argc; ++i)
51-
{
52-
if (std::string(argv[i]) == "--version")
53-
{
54-
return true;
55-
}
56-
}
57-
return false;
49+
auto logfile = std::getenv("JUPYTER_LOGFILE");
50+
if (logfile == nullptr)
51+
{
52+
return nullptr;
53+
}
54+
return xeus::make_file_logger(log_level, logfile);
5855
}
5956

60-
std::string extract_filename(int argc, char* argv[])
61-
{
62-
std::string res = "";
63-
for (int i = 0; i < argc; ++i)
64-
{
65-
if ((std::string(argv[i]) == "-f") && (i + 1 < argc))
66-
{
67-
res = argv[i + 1];
68-
for (int j = i; j < argc - 2; ++j)
69-
{
70-
argv[j] = argv[j + 2];
71-
}
72-
argc -= 2;
73-
break;
74-
}
75-
}
76-
return res;
77-
}
78-
79-
80-
8157
int main(int argc, char* argv[])
8258
{
83-
if (should_print_version(argc, argv))
59+
if (xeus::should_print_version(argc, argv))
8460
{
8561
std::clog << "xnelson " << XEUS_NELSON_VERSION << std::endl;
8662
return 0;
@@ -102,24 +78,29 @@ int main(int argc, char* argv[])
10278
signal(SIGSEGV, handler);
10379
#endif
10480

105-
auto context = xeus::make_context<zmq::context_t>();
81+
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
10682

10783
// Instantiating the xeus xinterpreter
10884
using interpreter_ptr = std::unique_ptr<xeus_nelson::interpreter>;
10985
interpreter_ptr interpreter = interpreter_ptr(new xeus_nelson::interpreter());
11086

87+
auto hist = xeus::make_in_memory_history_manager();
88+
auto logger = xeus::make_console_logger(xeus::xlogger::full, make_file_logger(xeus::xlogger::full));
11189

112-
std::string connection_filename = extract_filename(argc, argv);
90+
std::string connection_filename = xeus::extract_filename(argc, argv);
11391

11492
if (!connection_filename.empty())
11593
{
116-
11794
xeus::xconfiguration config = xeus::load_configuration(connection_filename);
95+
96+
std::cout << "Instantiating kernel" << std::endl;
11897
xeus::xkernel kernel(config,
11998
xeus::get_user_name(),
12099
std::move(context),
121100
std::move(interpreter),
122-
xeus::make_xserver_zmq);
101+
xeus::make_xserver_default,
102+
std::move(hist),
103+
std::move(logger));
123104

124105
std::cout <<
125106
"Starting xnelson kernel...\n\n"
@@ -134,26 +115,11 @@ int main(int argc, char* argv[])
134115
xeus::xkernel kernel(xeus::get_user_name(),
135116
std::move(context),
136117
std::move(interpreter),
137-
xeus::make_xserver_zmq);
118+
xeus::make_xserver_default);
138119

120+
std::cout << "Getting config" << std::endl;
139121
const auto& config = kernel.get_config();
140-
std::cout <<
141-
"Starting xnelson kernel...\n\n"
142-
"If you want to connect to this kernel from an other client, just copy"
143-
" and paste the following content inside of a `kernel.json` file. And then run for example:\n\n"
144-
"# jupyter console --existing kernel.json\n\n"
145-
"kernel.json\n```\n{\n"
146-
" \"transport\": \"" + config.m_transport + "\",\n"
147-
" \"ip\": \"" + config.m_ip + "\",\n"
148-
" \"control_port\": " + config.m_control_port + ",\n"
149-
" \"shell_port\": " + config.m_shell_port + ",\n"
150-
" \"stdin_port\": " + config.m_stdin_port + ",\n"
151-
" \"iopub_port\": " + config.m_iopub_port + ",\n"
152-
" \"hb_port\": " + config.m_hb_port + ",\n"
153-
" \"signature_scheme\": \"" + config.m_signature_scheme + "\",\n"
154-
" \"key\": \"" + config.m_key + "\"\n"
155-
"}\n```"
156-
<< std::endl;
122+
std::cout << xeus::get_start_message(config) << std::endl;
157123

158124
kernel.start();
159125
}

src/xinterpreter.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ namespace xeus_nelson
4141
Nelson::destroyMainEvaluator();
4242
}
4343

44-
nl::json interpreter::execute_request_impl(int execution_counter, // Typically the cell number
45-
const std::string & code, // Code to execute
46-
bool silent,
47-
bool /*store_history*/,
48-
nl::json /*user_expressions*/,
49-
bool /*allow_stdin*/)
44+
void interpreter::execute_request_impl(
45+
send_reply_callback cb,
46+
int execution_count,
47+
const std::string& code,
48+
xeus::execute_request_config config,
49+
nl::json /*user_expressions*/
50+
)
5051
{
5152
if (m_evaluator == nullptr)
5253
{
5354
const std::string evalue = "Nelson interpreter not initialized";
5455
std::vector<std::string> traceback({"Interpreter error: " + evalue});
55-
if(!silent)
56+
if(!config.silent)
5657
{
5758
publish_execution_error("Interpreter error", evalue, traceback);
5859
}
5960
// Compose error_reply message
60-
return xeus::create_error_reply("Interpreter error", evalue, traceback);
61+
cb(xeus::create_error_reply("Interpreter error", evalue, traceback));
6162
}
6263

6364
try
@@ -71,39 +72,39 @@ namespace xeus_nelson
7172
{
7273
const std::string evalue = "";
7374
std::vector<std::string> traceback({trimmed_output});
74-
if (!silent)
75+
if (!config.silent)
7576
{
7677
publish_execution_error("Interpreter error", evalue, traceback);
7778
}
7879
// Compose error_reply message
79-
return xeus::create_error_reply("Interpreter error", evalue, traceback);
80+
cb(xeus::create_error_reply("Interpreter error", evalue, traceback));
8081
}
8182
else
8283
{
83-
if (!silent && !trimmed_output.empty())
84+
if (!config.silent && !trimmed_output.empty())
8485
{
8586
nl::json pub_data;
8687
pub_data["text/plain"] = trimmed_output;
8788
// Publish the execution result
88-
publish_execution_result(execution_counter, std::move(pub_data), nl::json::object());
89+
publish_execution_result(execution_count, std::move(pub_data), nl::json::object());
8990
}
9091

9192
// TODO payload to set correctly or deprecated and not used anymore?
9293
//const nl::json& payload = nl::json::array();
9394
// Compose successful_reply message
94-
return xeus::create_successful_reply(nl::json::array(), nl::json::object());
95+
cb(xeus::create_successful_reply(nl::json::array(), nl::json::object()));
9596
}
9697
}
9798
catch (Nelson::Exception& e)
9899
{
99100
const auto evalue = Nelson::wstring_to_utf8(e.getMessage());
100101
std::vector<std::string> traceback({"Interpreter error: " + evalue});
101-
if (!silent)
102+
if (!config.silent)
102103
{
103104
publish_execution_error("Interpreter error", evalue, traceback);
104105
}
105106
// Compose error_reply message
106-
return xeus::create_error_reply("Interpreter error", evalue, traceback);
107+
cb(xeus::create_error_reply("Interpreter error", evalue, traceback));
107108
}
108109
}
109110

xeus-nelsonConfig.cmake.in

-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR};${CMAKE_MODULE_PATH}")
2222
@XEUS_NELSON_CONFIG_CODE@
2323

2424
include(CMakeFindDependencyMacro)
25-
find_dependency(xtl @xtl_REQUIRED_VERSION@)
2625
find_dependency(xeus-zmq @xeus-zmq_REQUIRED_VERSION@)
27-
find_dependency(cppzmq @cppzmq_REQUIRED_VERSION@)
2826

2927

3028
if (NOT TARGET xeus-nelson AND NOT TARGET xeus-nelson-static)

0 commit comments

Comments
 (0)