iruby 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc4c6b99aa811b7b1e6bf3e845c7dfa023dc26ce929dbc284836081d422c4b5f
4
- data.tar.gz: f68c0f62665ec6bb302e460885ca6e54e93f7102b3cdf699cb67143155a6181a
3
+ metadata.gz: 84f8ef4d7c7ae64831b901c85aa2e978bd07847c5707899bc82f7f3eed17a825
4
+ data.tar.gz: 2a2b12b2d7da7571a41286b3de58813c8f3173136bc47cd63516254682f76421
5
5
  SHA512:
6
- metadata.gz: 2de933258f837300d49209e51140276d9373ab6497c716cfe590d8e9e989d89a7e8e12410e4275c20d065e0fdfe1221c88074eb172bcadbab07c58077009d118
7
- data.tar.gz: 3dfa8d4abbe218873e42626056d68bc24e2372f153f18316eb152ce08aa1f95c68b301cb41f7cf154ae8b5bb94324e9071296ff67f90325aed5b08dfa123cecd
6
+ metadata.gz: '079c7183d157d4ca8177ca0025c4a8cfa95bb7cfa1497bfc2d65c9f4b38e00d92d4597ed54557c4ea03cfe56c93ed44768fa17b20fe29957078d8f4074e3f1c3'
7
+ data.tar.gz: 23a5d31658720706a3e5b2a9db90747e135a5ef473a8eadf554e6ceaa5eab1c0f035ba17161d1c10bcbeb952908b409c4d51144b23c566a15839c3d1574e7da9
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 0.6.1 (under development)
2
+
3
+ Bug Fixes:
4
+ * Follow the messages and hooks orders during execute_request processing (@mrkn)
5
+
1
6
  0.6.0 (2021-05-25)
2
7
 
3
8
  Bug Fixes:
data/lib/iruby/display.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  module IRuby
2
2
  module Display
3
3
  class << self
4
+ # @private
4
5
  def convert(obj, options)
5
6
  Representation.new(obj, options)
6
7
  end
7
8
 
9
+ # @private
8
10
  def display(obj, options = {})
9
11
  obj = convert(obj, options)
10
12
  options = obj.options
@@ -37,6 +39,7 @@ module IRuby
37
39
  data
38
40
  end
39
41
 
42
+ # @private
40
43
  def clear_output(wait = false)
41
44
  IRuby::Kernel.instance.session.send(:publish, :clear_output, wait: wait)
42
45
  end
data/lib/iruby/kernel.rb CHANGED
@@ -8,10 +8,26 @@ module IRuby
8
8
  @events = EventManager.new([:initialized])
9
9
 
10
10
  class << self
11
+ # Return the event manager defined in the `IRuby::Kernel` class.
12
+ # This event manager can handle the following event:
13
+ #
14
+ # - `initialized`: The event occurred after the initialization of
15
+ # a `IRuby::Kernel` instance is finished
16
+ #
17
+ # @example Registering initialized event
18
+ # IRuby::Kernel.events.register(:initialized) do |result|
19
+ # STDERR.puts "IRuby kernel has been initialized"
20
+ # end
21
+ #
22
+ # @see IRuby::EventManager
23
+ # @see IRuby::Kernel#events
11
24
  attr_reader :events
25
+
26
+ # Returns the singleton kernel instance
12
27
  attr_accessor :instance
13
28
  end
14
29
 
30
+ # Returns a session object
15
31
  attr_reader :session
16
32
 
17
33
  EVENTS = [
@@ -40,8 +56,35 @@ module IRuby
40
56
  self.class.events.trigger(:initialized, self)
41
57
  end
42
58
 
59
+ # Returns the event manager defined in a `IRuby::Kernel` instance.
60
+ # This event manager can handle the following events:
61
+ #
62
+ # - `pre_execute`: The event occurred before running the code
63
+ #
64
+ # - `pre_run_cell`: The event occurred before running the code and
65
+ # if the code execution is not silent
66
+ #
67
+ # - `post_execute`: The event occurred after running the code
68
+ #
69
+ # - `post_run_cell`: The event occurred after running the code and
70
+ # if the code execution is not silent
71
+ #
72
+ # The callback functions of `pre_run_cell` event must take one argument
73
+ # to get an `ExecutionInfo` object.
74
+ # The callback functions of `post_run_cell` event must take one argument
75
+ # to get the result of the code execution.
76
+ #
77
+ # @example Registering post_run_cell event
78
+ # IRuby::Kernel.instance.events.register(:post_run_cell) do |result|
79
+ # STDERR.puts "The result of the last execution: %p" % result
80
+ # end
81
+ #
82
+ # @see IRuby::EventManager
83
+ # @see IRuby::ExecutionInfo
84
+ # @see IRuby::Kernel.events
43
85
  attr_reader :events
44
86
 
87
+ # @private
45
88
  def create_backend
46
89
  PryBackend.new
47
90
  rescue Exception => e
@@ -49,6 +92,7 @@ module IRuby
49
92
  PlainBackend.new
50
93
  end
51
94
 
95
+ # @private
52
96
  def run
53
97
  send_status :starting
54
98
  while @running
@@ -56,6 +100,7 @@ module IRuby
56
100
  end
57
101
  end
58
102
 
103
+ # @private
59
104
  def dispatch
60
105
  msg = @session.recv(:reply)
61
106
  IRuby.logger.debug "Kernel#dispatch: msg = #{msg}"
@@ -72,6 +117,7 @@ module IRuby
72
117
  @session.send(:publish, :error, error_content(e))
73
118
  end
74
119
 
120
+ # @private
75
121
  def kernel_info_request(msg)
76
122
  @session.send(:reply, :kernel_info_reply,
77
123
  protocol_version: '5.0',
@@ -93,11 +139,13 @@ module IRuby
93
139
  status: :ok)
94
140
  end
95
141
 
142
+ # @private
96
143
  def send_status(status)
97
144
  IRuby.logger.debug "Send status: #{status}"
98
145
  @session.send(:publish, :status, execution_state: status)
99
146
  end
100
147
 
148
+ # @private
101
149
  def execute_request(msg)
102
150
  code = msg[:content]['code']
103
151
  store_history = msg[:content]['store_history']
@@ -134,16 +182,20 @@ module IRuby
134
182
  content[:execution_count] = @execution_count
135
183
  end
136
184
 
185
+ unless result.nil? || silent
186
+ @session.send(:publish, :execute_result,
187
+ data: Display.display(result),
188
+ metadata: {},
189
+ execution_count: @execution_count)
190
+ end
191
+
137
192
  events.trigger(:post_execute)
138
193
  events.trigger(:post_run_cell, result) unless silent
139
194
 
140
195
  @session.send(:reply, :execute_reply, content)
141
- @session.send(:publish, :execute_result,
142
- data: Display.display(result),
143
- metadata: {},
144
- execution_count: @execution_count) unless result.nil? || msg[:content]['silent']
145
196
  end
146
197
 
198
+ # @private
147
199
  def error_content(e)
148
200
  rindex = e.backtrace.rindex{|line| line.start_with?(@backend.eval_path)} || -1
149
201
  backtrace = SyntaxError === e && rindex == -1 ? [] : e.backtrace[0..rindex]
@@ -152,12 +204,14 @@ module IRuby
152
204
  traceback: ["#{RED}#{e.class}#{RESET}: #{e.message}", *backtrace] }
153
205
  end
154
206
 
207
+ # @private
155
208
  def is_complete_request(msg)
156
209
  # FIXME: the code completeness should be judged by using ripper or other Ruby parser
157
210
  @session.send(:reply, :is_complete_reply,
158
211
  status: :unknown)
159
212
  end
160
213
 
214
+ # @private
161
215
  def complete_request(msg)
162
216
  # HACK for #26, only complete last line
163
217
  code = msg[:content]['code']
@@ -173,36 +227,43 @@ module IRuby
173
227
  status: :ok)
174
228
  end
175
229
 
230
+ # @private
176
231
  def connect_request(msg)
177
232
  @session.send(:reply, :connect_reply, Hash[%w(shell_port iopub_port stdin_port hb_port).map {|k| [k, @config[k]] }])
178
233
  end
179
234
 
235
+ # @private
180
236
  def shutdown_request(msg)
181
237
  @session.send(:reply, :shutdown_reply, msg[:content])
182
238
  @running = false
183
239
  end
184
240
 
241
+ # @private
185
242
  def history_request(msg)
186
243
  # we will just send back empty history for now, pending clarification
187
244
  # as requested in ipython/ipython#3806
188
245
  @session.send(:reply, :history_reply, history: [])
189
246
  end
190
247
 
248
+ # @private
191
249
  def inspect_request(msg)
192
250
  # not yet implemented. See (#119).
193
251
  @session.send(:reply, :inspect_reply, status: :ok, found: false, data: {}, metadata: {})
194
252
  end
195
253
 
254
+ # @private
196
255
  def comm_open(msg)
197
256
  comm_id = msg[:content]['comm_id']
198
257
  target_name = msg[:content]['target_name']
199
258
  Comm.comm[comm_id] = Comm.target[target_name].new(target_name, comm_id)
200
259
  end
201
260
 
261
+ # @private
202
262
  def comm_msg(msg)
203
263
  Comm.comm[msg[:content]['comm_id']].handle_msg(msg[:content]['data'])
204
264
  end
205
265
 
266
+ # @private
206
267
  def comm_close(msg)
207
268
  comm_id = msg[:content]['comm_id']
208
269
  Comm.comm[comm_id].handle_close(msg[:content]['data'])
data/lib/iruby/utils.rb CHANGED
@@ -4,37 +4,45 @@ module IRuby
4
4
  Display.convert(object, options)
5
5
  end
6
6
 
7
+ # Display the object
7
8
  def display(obj, options = {})
8
9
  Kernel.instance.session.send(:publish, :display_data,
9
10
  data: Display.display(obj, options),
10
11
  metadata: {}) unless obj.nil?
11
12
  end
12
13
 
14
+ # Clear the output area
13
15
  def clear_output(wait=false)
14
16
  Display.clear_output(wait)
15
17
  end
16
18
 
19
+ # Format the given object into HTML table
17
20
  def table(s, **options)
18
21
  html(HTML.table(s, options))
19
22
  end
20
23
 
24
+ # Treat the given string as LaTeX text
21
25
  def latex(s)
22
26
  convert(s, mime: 'text/latex')
23
27
  end
24
28
  alias tex latex
25
29
 
30
+ # Format the given string of TeX equation into LaTeX text
26
31
  def math(s)
27
32
  convert("$$#{s}$$", mime: 'text/latex')
28
33
  end
29
34
 
35
+ # Treat the given string as HTML
30
36
  def html(s)
31
37
  convert(s, mime: 'text/html')
32
38
  end
33
39
 
40
+ # Treat the given string as JavaScript code
34
41
  def javascript(s)
35
42
  convert(s, mime: 'application/javascript')
36
43
  end
37
44
 
45
+ # Treat the given string as SVG text
38
46
  def svg(s)
39
47
  convert(s, mime: 'image/svg+xml')
40
48
  end
data/lib/iruby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IRuby
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -70,7 +70,7 @@ module IRubyTest
70
70
  @kernel.execute_request(msg)
71
71
 
72
72
  assert_equal({
73
- msg_types: [ "execute_input", "execute_reply", "execute_result" ],
73
+ msg_types: [ "execute_input", "execute_result", "execute_reply" ],
74
74
  execute_reply: {
75
75
  status: "ok",
76
76
  user_expressions: {},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-25 00:00:00.000000000 Z
12
+ date: 2021-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: data_uri