6
6
* The full license is in the file LICENSE, distributed with this software.
7
7
****************************************************************************/
8
8
9
-
10
-
11
9
#include < cstdlib>
12
10
#include < iostream>
13
11
#include < string>
23
21
24
22
#include " xeus/xkernel.hpp"
25
23
#include " xeus/xkernel_configuration.hpp"
26
- #include " xeus-zmq/xserver_zmq .hpp"
24
+ #include < xeus/xhelper .hpp>
27
25
26
+ #include " xeus-zmq/xserver_zmq.hpp"
27
+ #include " xeus-zmq/xzmq_context.hpp"
28
28
29
29
#include " xeus-nelson/xinterpreter.hpp"
30
30
#include " xeus-nelson/xeus_nelson_config.hpp"
31
31
32
-
33
32
#ifdef __GNUC__
34
33
void handler (int sig)
35
34
{
@@ -45,42 +44,19 @@ void handler(int sig)
45
44
}
46
45
#endif
47
46
48
- bool should_print_version ( int argc, char * argv[] )
47
+ std::unique_ptr<xeus::xlogger> make_file_logger (xeus::xlogger::level log_level )
49
48
{
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);
58
55
}
59
56
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
-
81
57
int main (int argc, char * argv[])
82
58
{
83
- if (should_print_version (argc, argv))
59
+ if (xeus:: should_print_version (argc, argv))
84
60
{
85
61
std::clog << " xnelson " << XEUS_NELSON_VERSION << std::endl;
86
62
return 0 ;
@@ -102,24 +78,29 @@ int main(int argc, char* argv[])
102
78
signal (SIGSEGV, handler);
103
79
#endif
104
80
105
- auto context = xeus::make_context<zmq:: context_t > ();
81
+ std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context ();
106
82
107
83
// Instantiating the xeus xinterpreter
108
84
using interpreter_ptr = std::unique_ptr<xeus_nelson::interpreter>;
109
85
interpreter_ptr interpreter = interpreter_ptr (new xeus_nelson::interpreter ());
110
86
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));
111
89
112
- std::string connection_filename = extract_filename (argc, argv);
90
+ std::string connection_filename = xeus:: extract_filename (argc, argv);
113
91
114
92
if (!connection_filename.empty ())
115
93
{
116
-
117
94
xeus::xconfiguration config = xeus::load_configuration (connection_filename);
95
+
96
+ std::cout << " Instantiating kernel" << std::endl;
118
97
xeus::xkernel kernel (config,
119
98
xeus::get_user_name (),
120
99
std::move (context),
121
100
std::move (interpreter),
122
- xeus::make_xserver_zmq);
101
+ xeus::make_xserver_default,
102
+ std::move (hist),
103
+ std::move (logger));
123
104
124
105
std::cout <<
125
106
" Starting xnelson kernel...\n\n "
@@ -134,26 +115,11 @@ int main(int argc, char* argv[])
134
115
xeus::xkernel kernel (xeus::get_user_name (),
135
116
std::move (context),
136
117
std::move (interpreter),
137
- xeus::make_xserver_zmq );
118
+ xeus::make_xserver_default );
138
119
120
+ std::cout << " Getting config" << std::endl;
139
121
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;
157
123
158
124
kernel.start ();
159
125
}
0 commit comments