Skip to content

Commit

Permalink
Update to xeus 5
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Jul 10, 2024
1 parent 6a7109a commit 9f54125
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 39 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# ##################################################################################################

cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.24)
project(xeus-octave)

set(XEUS_OCTAVE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down Expand Up @@ -71,6 +71,8 @@ option(
# Dependencies
# ============

set(xeus_zmq_REQUIRED_VERSION 3.0.0)

find_package(xeus-zmq REQUIRED)
find_package(PNG REQUIRED)
find_package(glad REQUIRED)
Expand Down Expand Up @@ -225,7 +227,7 @@ macro(xeus_octave_create_target target_name linkage output_name)

target_link_libraries(
${target_name}
PUBLIC xtl PkgConfig::octinterp
PUBLIC PkgConfig::octinterp
PRIVATE glad::glad glfw PNG::PNG
)
if(XEUS_OCTAVE_USE_SHARED_XEUS)
Expand Down
10 changes: 5 additions & 5 deletions environment-dev.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: xeus-octave
channels:
- conda-forge
dependencies:
Expand All @@ -9,10 +10,9 @@ dependencies:
- pkg-config
# Host dependencies
- libuuid
- xtl
- xeus-zmq >=1.3.0,<2
- nlohmann_json
- cppzmq
- xeus>=5.0.0
- xeus-zmq>=3.0,<4.0
- nlohmann_json=3.11.3
- octave =8.*
- glad
- glfw
Expand All @@ -21,7 +21,7 @@ dependencies:
- pre-commit
- clang-tools
- clang
- jupyter_kernel_test >=0.4.3
- jupyter_kernel_test>=0.5,<0.6
- nbval
- pytest
- pytest-rerunfailures
Expand Down
1 change: 0 additions & 1 deletion include/xeus-octave/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <iostream>

#include <xeus/xguid.hpp>
#include <xtl/xoptional.hpp>

namespace xeus_octave::utils
{
Expand Down
9 changes: 4 additions & 5 deletions include/xeus-octave/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ class xoctave_interpreter : public xeus::xinterpreter

void configure_impl() override;

nl::json execute_request_impl(
void execute_request_impl(
send_reply_callback cb,
int execution_counter,
std::string const& 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(std::string const& code, int cursor_pos) override;
Expand Down
93 changes: 81 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
#include <memory>
#include <string_view>

#ifdef __GNUC__
#include <execinfo.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif

#include "xeus-zmq/xzmq_context.hpp"
#include <xeus-zmq/xserver_zmq.hpp>
#include <xeus/xeus_context.hpp>
#include <xeus/xhelper.hpp>
Expand All @@ -31,6 +40,29 @@
#include "xeus-octave/config.hpp"
#include "xeus-octave/xinterpreter.hpp"

#ifdef __GNUC__
void handler(int sig)
{
void* array[10];
// get void*'s for all entries on the stack
int size = backtrace(array, 10);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
#endif

std::unique_ptr<xeus::xlogger> make_file_logger(xeus::xlogger::level log_level)
{
auto logfile = std::getenv("JUPYTER_LOGFILE");
if (logfile == nullptr)
{
return nullptr;
}
return xeus::make_file_logger(log_level, logfile);
}

int main(int argc, char* argv[])
{

Expand All @@ -52,19 +84,56 @@ int main(int argc, char* argv[])
}
#endif

// Registering SIGSEGV handler
#ifdef __GNUC__
std::clog << "registering handler for SIGSEGV" << std::endl;
signal(SIGSEGV, handler);
#endif

std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
auto interpreter = xeus::xkernel::interpreter_ptr(new xeus_octave::xoctave_interpreter());
xeus::register_interpreter(interpreter.get());
auto config = xeus::load_configuration(xeus::extract_filename(argc, argv));
std::cout << xeus::print_starting_message(config);

auto kernel = xeus::xkernel(
/* config= */ std::move(config),
/* user_name= */ xeus::get_user_name(),
/* context= */ xeus::make_context<zmq::context_t>(),
/* interpreter= */ std::move(interpreter),
/* sbuilder= */ xeus::make_xserver_zmq
);
kernel.start();
auto hist = xeus::make_in_memory_history_manager();
auto logger = xeus::make_console_logger(xeus::xlogger::full, make_file_logger(xeus::xlogger::full));

std::string connection_filename = xeus::extract_filename(argc, argv);

if (!connection_filename.empty())
{
xeus::xconfiguration config = xeus::load_configuration(connection_filename);

std::cout << "Instantiating kernel" << std::endl;
auto kernel = xeus::xkernel(
/* config= */ std::move(config),
/* user_name= */ xeus::get_user_name(),
/* context= */ std::move(context),
/* interpreter= */ std::move(interpreter),
/* sbuilder= */ xeus::make_xserver_default,
/* history_manager= */ std::move(hist),
/* logger= */ std::move(logger)
);

std::cout << "Starting xoctave kernel...\n\n"
"If you want to connect to this kernel from an other client, you can use"
" the " +
connection_filename + " file."
<< std::endl;
kernel.start();
}
else
{
auto kernel = xeus::xkernel(
/* user_name= */ xeus::get_user_name(),
/* context= */ std::move(context),
/* interpreter= */ std::move(interpreter),
/* sbuilder= */ xeus::make_xserver_default
);

std::cout << "Getting config" << std::endl;
auto const& config = kernel.get_config();
std::cout << xeus::get_start_message(config);
kernel.start();
}

return 0;
}
}
4 changes: 2 additions & 2 deletions src/tk_notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <octave/interpreter.h>
#include <octave/ov.h>
#include <png.h>
#include <xtl/xbase64.hpp>
#include <xeus/xbase64.hpp>

#include "xeus-octave/plotstream.hpp"
#include "xeus-octave/tk_notebook.hpp"
Expand Down Expand Up @@ -310,7 +310,7 @@ void notebook_graphics_toolkit::send_figure(

nl::json data, meta, tran;

data["image/png"] = xtl::base64encode(std::string(img.begin(), img.end()));
data["image/png"] = xeus::base64encode(std::string(img.begin(), img.end()));
// Send real width and height through metadata for optimal scaling
meta["image/png"] = {
{"width", width / dpr},
Expand Down
23 changes: 11 additions & 12 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,24 @@ void fix_parse_error(std::string& evalue, std::string const& code, int line, int

} // namespace

nl::json xoctave_interpreter::execute_request_impl(
int execution_counter,
void xoctave_interpreter::execute_request_impl(
send_reply_callback cb,
int execution_count,
std::string const& code,
bool silent,
bool /*store_history*/,
nl::json /*user_expressions*/,
bool allow_stdin
xeus::execute_request_config config,
nl::json /*user_expressions*/
)
{
class parser : public oc::parser
{
public:

parser(int execution_counter, std::string const& eval_string, oc::interpreter& interp) :
parser(int execution_count, std::string const& eval_string, oc::interpreter& interp) :
oc::parser(eval_string, interp)
{
m_lexer.m_force_script = true;
m_lexer.prep_for_file();
m_lexer.m_fcn_file_name = m_lexer.m_fcn_file_full_name = "cell[" + std::to_string(execution_counter) + "]";
m_lexer.m_fcn_file_name = m_lexer.m_fcn_file_full_name = "cell[" + std::to_string(execution_count) + "]";
}

octave_value primary_fcn() { return m_primary_fcn; }
Expand All @@ -306,8 +305,8 @@ nl::json xoctave_interpreter::execute_request_impl(
#endif
nl::json result;

m_silent = silent;
m_allow_stdin = allow_stdin;
m_silent = config.silent;
m_allow_stdin = config.allow_stdin;

result = xeus::create_successful_reply();

Expand Down Expand Up @@ -338,7 +337,7 @@ nl::json xoctave_interpreter::execute_request_impl(
else
{
// Execute code
auto str_parser = parser(execution_counter, code, interpreter);
auto str_parser = parser(execution_count, code, interpreter);

// Clear current figure
// This is useful for creating a figure in every cell, otherwise running code
Expand Down Expand Up @@ -411,7 +410,7 @@ nl::json xoctave_interpreter::execute_request_impl(
// Update the figure if present
interpreter.feval("drawnow");

return result;
cb(result);
}

void xoctave_interpreter::configure_impl()
Expand Down

0 comments on commit 9f54125

Please sign in to comment.