iruby 0.3 → 0.7.0

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.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ubuntu.yml +62 -0
  3. data/CHANGES.md +203 -0
  4. data/Gemfile +3 -1
  5. data/LICENSE +1 -1
  6. data/README.md +137 -87
  7. data/Rakefile +36 -10
  8. data/ci/Dockerfile.base.erb +41 -0
  9. data/ci/Dockerfile.main.erb +7 -0
  10. data/ci/requirements.txt +1 -0
  11. data/docker/setup.sh +15 -0
  12. data/docker/test.sh +7 -0
  13. data/iruby.gemspec +14 -18
  14. data/lib/iruby.rb +14 -8
  15. data/lib/iruby/backend.rb +38 -10
  16. data/lib/iruby/command.rb +67 -15
  17. data/lib/iruby/display.rb +77 -41
  18. data/lib/iruby/event_manager.rb +40 -0
  19. data/lib/iruby/formatter.rb +3 -3
  20. data/lib/iruby/input.rb +6 -6
  21. data/lib/iruby/input/README.md +299 -0
  22. data/lib/iruby/input/autoload.rb +1 -1
  23. data/lib/iruby/input/builder.rb +4 -4
  24. data/lib/iruby/input/button.rb +2 -2
  25. data/lib/iruby/input/cancel.rb +1 -1
  26. data/lib/iruby/input/checkbox.rb +3 -3
  27. data/lib/iruby/input/date.rb +3 -3
  28. data/lib/iruby/input/field.rb +2 -2
  29. data/lib/iruby/input/file.rb +3 -3
  30. data/lib/iruby/input/form.rb +6 -6
  31. data/lib/iruby/input/label.rb +4 -4
  32. data/lib/iruby/input/multiple.rb +10 -10
  33. data/lib/iruby/input/popup.rb +2 -2
  34. data/lib/iruby/input/radio.rb +6 -6
  35. data/lib/iruby/input/select.rb +8 -8
  36. data/lib/iruby/input/textarea.rb +1 -1
  37. data/lib/iruby/input/widget.rb +2 -2
  38. data/lib/iruby/jupyter.rb +77 -0
  39. data/lib/iruby/kernel.rb +204 -36
  40. data/lib/iruby/ostream.rb +29 -8
  41. data/lib/iruby/session.rb +117 -0
  42. data/lib/iruby/session/cztop.rb +4 -0
  43. data/lib/iruby/session_adapter.rb +72 -0
  44. data/lib/iruby/session_adapter/cztop_adapter.rb +45 -0
  45. data/lib/iruby/session_adapter/ffirzmq_adapter.rb +55 -0
  46. data/lib/iruby/session_adapter/pyzmq_adapter.rb +77 -0
  47. data/lib/iruby/session_adapter/test_adapter.rb +49 -0
  48. data/lib/iruby/utils.rb +13 -2
  49. data/lib/iruby/version.rb +1 -1
  50. data/run-test.sh +12 -0
  51. data/tasks/ci.rake +65 -0
  52. data/test/helper.rb +136 -0
  53. data/test/integration_test.rb +22 -11
  54. data/test/iruby/backend_test.rb +37 -0
  55. data/test/iruby/command_test.rb +207 -0
  56. data/test/iruby/event_manager_test.rb +92 -0
  57. data/test/iruby/jupyter_test.rb +27 -0
  58. data/test/iruby/kernel_test.rb +185 -0
  59. data/test/iruby/mime_test.rb +50 -0
  60. data/test/iruby/multi_logger_test.rb +1 -5
  61. data/test/iruby/session_adapter/cztop_adapter_test.rb +20 -0
  62. data/test/iruby/session_adapter/ffirzmq_adapter_test.rb +20 -0
  63. data/test/iruby/session_adapter/session_adapter_test_base.rb +27 -0
  64. data/test/iruby/session_adapter_test.rb +91 -0
  65. data/test/iruby/session_test.rb +48 -0
  66. data/test/run-test.rb +19 -0
  67. metadata +120 -50
  68. data/.travis.yml +0 -16
  69. data/CHANGES +0 -143
  70. data/CONTRIBUTORS +0 -19
  71. data/lib/iruby/session/rbczmq.rb +0 -68
  72. data/test/test_helper.rb +0 -5
@@ -2,7 +2,7 @@ begin
2
2
  require 'erector'
3
3
  rescue LoadError
4
4
  raise LoadError, <<-ERROR.gsub(/\s+/,' ')
5
- IRuby::Input requires the erector gem.
5
+ IRuby::Input requires the erector gem.
6
6
  `gem install erector` or add `gem 'erector'`
7
7
  it to your Gemfile to continue.
8
8
  ERROR
@@ -21,7 +21,7 @@ module IRuby
21
21
  def html &block
22
22
  add_field Class.new(Widget) {
23
23
  define_method(:widget_html) { instance_eval &block }
24
- }.new
24
+ }.new
25
25
  end
26
26
 
27
27
  def text string
@@ -44,7 +44,7 @@ module IRuby
44
44
  end
45
45
  end
46
46
 
47
- private
47
+ private
48
48
 
49
49
  def process key, &block
50
50
  @processors[key.to_s] = block
@@ -52,14 +52,14 @@ module IRuby
52
52
 
53
53
  def unique_key key
54
54
  @keys ||= []
55
-
55
+
56
56
  if @keys.include? key
57
57
  (2..Float::INFINITY).each do |i|
58
58
  test = "#{key}#{i}"
59
59
  break key = test unless @keys.include? test
60
60
  end
61
61
  end
62
-
62
+
63
63
  @keys << key; key
64
64
  end
65
65
  end
@@ -10,7 +10,7 @@ module IRuby
10
10
  green: 'success',
11
11
  aqua: 'info',
12
12
  orange: 'warning',
13
- red: 'danger',
13
+ red: 'danger',
14
14
  none: 'link'
15
15
  }
16
16
 
@@ -37,7 +37,7 @@ module IRuby
37
37
  def widget_html
38
38
  button(
39
39
  @label || to_label(@key),
40
- type: 'button',
40
+ type: 'button',
41
41
  :'data-iruby-key' => @key,
42
42
  class: "btn btn-#{COLORS[@color]} pull-right #{@js_class}"
43
43
  )
@@ -22,7 +22,7 @@ module IRuby
22
22
  def widget_html
23
23
  button(
24
24
  @label,
25
- type: 'button',
25
+ type: 'button',
26
26
  :'data-dismiss' => 'modal',
27
27
  class: "btn btn-danger pull-right iruby-cancel"
28
28
  )
@@ -56,10 +56,10 @@ module IRuby
56
56
  widget_label do
57
57
  div **params do
58
58
  @options.each do |option|
59
- label class: 'checkbox-inline' do
59
+ label class: 'checkbox-inline' do
60
60
  input(
61
- name: @key,
62
- value: option,
61
+ name: @key,
62
+ value: option,
63
63
  type: 'checkbox',
64
64
  checked: @default.include?(option)
65
65
  )
@@ -6,7 +6,7 @@ module IRuby
6
6
  builder :date do |key='date', **params|
7
7
  params[:default] ||= false
8
8
  params[:key] = unique_key key
9
-
9
+
10
10
  if params[:default].is_a? Time
11
11
  params[:default] = params[:default].strftime('%m/%d/%Y')
12
12
  end
@@ -22,13 +22,13 @@ module IRuby
22
22
  '#ui-datepicker-div { z-index: 2000 !important; }'
23
23
  end
24
24
 
25
- def widget_js
25
+ def widget_js
26
26
  <<-JS
27
27
  $('.iruby-date').datepicker({
28
28
  dateFormat: 'mm/dd/yy',
29
29
  onClose: function(date) {
30
30
  $(this).data('iruby-value', date);
31
- }
31
+ }
32
32
  });
33
33
  JS
34
34
  end
@@ -17,9 +17,9 @@ module IRuby
17
17
  end
18
18
 
19
19
  def widget_html
20
- widget_label do
20
+ widget_label do
21
21
  input(
22
- type: @type,
22
+ type: @type,
23
23
  :'data-iruby-key' => @key,
24
24
  class: "form-control #{@js_class}",
25
25
  value: @default
@@ -13,10 +13,10 @@ module IRuby
13
13
 
14
14
  # get rid of Chrome's silly path
15
15
  name = value['name'].sub('C:\\fakepath\\','')
16
-
16
+
17
17
  result[key.to_sym] = {
18
18
  name: name,
19
- data: uri.data,
19
+ data: uri.data,
20
20
  content_type: uri.content_type
21
21
  }
22
22
  end
@@ -46,7 +46,7 @@ module IRuby
46
46
  def widget_html
47
47
  widget_label do
48
48
  input(
49
- type: 'file',
49
+ type: 'file',
50
50
  :'data-iruby-key' => @key,
51
51
  class: 'form-control iruby-file'
52
52
  )
@@ -5,7 +5,7 @@ module IRuby
5
5
  class InputForm < Widget
6
6
  needs :fields, buttons: []
7
7
 
8
- def widget_js
8
+ def widget_js
9
9
  javascript = <<-JS
10
10
  var remove = function () {
11
11
  Jupyter.notebook.kernel.send_input_reply(
@@ -14,7 +14,7 @@ module IRuby
14
14
  })
15
15
  );
16
16
  };
17
-
17
+
18
18
  $("#iruby-form").on("remove", remove);
19
19
 
20
20
  $('#iruby-form').submit(function() {
@@ -33,16 +33,16 @@ module IRuby
33
33
  Jupyter.notebook.kernel.send_input_reply(
34
34
  JSON.stringify({'#{@id}': result})
35
35
  );
36
-
36
+
37
37
  $(this).remove();
38
38
  return false;
39
39
  });
40
40
 
41
41
  $('#iruby-form').keydown(function(event) {
42
- if (event.keyCode == 13 && !event.shiftKey) {
42
+ if (event.keyCode == 13 && !event.shiftKey) {
43
43
  $('#iruby-form').submit();
44
- } else if (event.keyCode == 27) {
45
- $('#iruby-form').remove();
44
+ } else if (event.keyCode == 27) {
45
+ $('#iruby-form').remove();
46
46
  }
47
47
  });
48
48
  JS
@@ -4,13 +4,13 @@ module IRuby
4
4
  needs label: nil, icon: nil
5
5
 
6
6
  def widget_label
7
- div class: 'iruby-label input-group' do
8
- span class: 'input-group-addon' do
7
+ div class: 'iruby-label input-group' do
8
+ span class: 'input-group-addon' do
9
9
  text @label || to_label(@key)
10
10
  end
11
-
11
+
12
12
  yield
13
-
13
+
14
14
  if @icon
15
15
  span @icon, class: "input-group-addon"
16
16
  end
@@ -9,7 +9,7 @@ module IRuby
9
9
 
10
10
  params[:key] = unique_key(key)
11
11
  params[:options] = args
12
-
12
+
13
13
  params[:default] = case params[:default]
14
14
  when false, nil
15
15
  []
@@ -24,12 +24,12 @@ module IRuby
24
24
 
25
25
  def widget_css
26
26
  <<-CSS
27
- .iruby-multiple {
27
+ .iruby-multiple {
28
28
  display: table;
29
29
  min-width: 25%;
30
30
  }
31
- .form-control.iruby-multiple-container {
32
- display: table;
31
+ .form-control.iruby-multiple-container {
32
+ display: table;
33
33
  }
34
34
  CSS
35
35
  end
@@ -54,17 +54,17 @@ module IRuby
54
54
  end
55
55
 
56
56
  def widget_html
57
- widget_label do
58
- div class: 'form-control iruby-multiple-container' do
57
+ widget_label do
58
+ div class: 'form-control iruby-multiple-container' do
59
59
  params = {
60
60
  size: @size,
61
61
  multiple: true,
62
- class: 'iruby-multiple',
62
+ class: 'iruby-multiple',
63
63
  :'data-iruby-key' => @key
64
64
  }
65
-
66
- select **params do
67
- @options.each do |o|
65
+
66
+ select **params do
67
+ @options.each do |o|
68
68
  option o, selected: @default.include?(o)
69
69
  end
70
70
  end
@@ -21,11 +21,11 @@ module IRuby
21
21
  #{widget_join :widget_js, @form, *@buttons}
22
22
 
23
23
  var popup = $(this);
24
-
24
+
25
25
  $('#iruby-form').submit(function() {
26
26
  popup.modal('hide');
27
27
  });
28
-
28
+
29
29
  Jupyter.notebook.keyboard_manager.disable();
30
30
  }
31
31
  });
@@ -6,7 +6,7 @@ module IRuby
6
6
  builder :radio do |*args, **params|
7
7
  key = :radio
8
8
  key, *args = args if args.first.is_a? Symbol
9
-
9
+
10
10
  params[:key] = unique_key(key)
11
11
  params[:options] = args
12
12
  params[:default] ||= false
@@ -24,7 +24,7 @@ module IRuby
24
24
  <<-JS
25
25
  $('.iruby-radio input').change(function(){
26
26
  var parent = $(this).closest('.iruby-radio');
27
- $(parent).data('iruby-value',
27
+ $(parent).data('iruby-value',
28
28
  $(parent).find(':checked').val()
29
29
  );
30
30
  });
@@ -38,13 +38,13 @@ module IRuby
38
38
  :'data-iruby-value' => @options.first,
39
39
  class: 'iruby-radio form-control'
40
40
  }
41
- widget_label do
41
+ widget_label do
42
42
  div **params do
43
43
  @options.each do |option|
44
- label class: 'radio-inline' do
44
+ label class: 'radio-inline' do
45
45
  input(
46
- name: @key,
47
- value: option,
46
+ name: @key,
47
+ value: option,
48
48
  type: 'radio',
49
49
  checked: @default == option
50
50
  )
@@ -20,7 +20,7 @@ module IRuby
20
20
 
21
21
  def widget_css
22
22
  <<-CSS
23
- .iruby-select {
23
+ .iruby-select {
24
24
  min-width: 25%;
25
25
  margin-left: 0 !important;
26
26
  }
@@ -30,7 +30,7 @@ module IRuby
30
30
  def widget_js
31
31
  <<-JS
32
32
  $('.iruby-select').change(function(){
33
- $(this).data('iruby-value',
33
+ $(this).data('iruby-value',
34
34
  $(this).find('option:selected').text()
35
35
  );
36
36
  });
@@ -38,16 +38,16 @@ module IRuby
38
38
  end
39
39
 
40
40
  def widget_html
41
- widget_label do
42
- div class: 'form-control' do
41
+ widget_label do
42
+ div class: 'form-control' do
43
43
  params = {
44
- class: 'iruby-select',
44
+ class: 'iruby-select',
45
45
  :'data-iruby-key' => @key,
46
46
  :'data-iruby-value' => @default
47
47
  }
48
-
49
- select **params do
50
- @options.each do |o|
48
+
49
+ select **params do
50
+ @options.each do |o|
51
51
  option o, selected: @default == o
52
52
  end
53
53
  end
@@ -9,7 +9,7 @@ module IRuby
9
9
  end
10
10
 
11
11
  def widget_html
12
- widget_label do
12
+ widget_label do
13
13
  textarea(
14
14
  @default,
15
15
  rows: @rows,
@@ -9,13 +9,13 @@ module IRuby
9
9
  def content; widget_html; end
10
10
 
11
11
  def self.builder method, &block
12
- Builder.instance_eval do
12
+ Builder.instance_eval do
13
13
  define_method method, &block
14
14
  end
15
15
  end
16
16
 
17
17
  def widget_join method, *args
18
- strings = args.map do |arg|
18
+ strings = args.map do |arg|
19
19
  arg.is_a?(String) ? arg : arg.send(method)
20
20
  end
21
21
  strings.uniq.join("\n")
@@ -0,0 +1,77 @@
1
+ module IRuby
2
+ module Jupyter
3
+ class << self
4
+ # User's default kernelspec directory is described here:
5
+ # https://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html
6
+ def default_data_dir
7
+ case
8
+ when windows?
9
+ appdata = windows_user_appdata
10
+ if !appdata.empty?
11
+ File.join(appdata, 'jupyter')
12
+ else
13
+ jupyter_config_dir = ENV.fetch('JUPYTER_CONFIG_DIR', File.expand_path('~/.jupyter'))
14
+ File.join(jupyter_config_dir, 'data')
15
+ end
16
+ when apple?
17
+ File.expand_path('~/Library/Jupyter')
18
+ else
19
+ xdg_data_home = ENV.fetch('XDG_DATA_HOME', '')
20
+ data_home = xdg_data_home[0] ? xdg_data_home : File.expand_path('~/.local/share')
21
+ File.join(data_home, 'jupyter')
22
+ end
23
+ end
24
+
25
+ def kernelspec_dir(data_dir=nil)
26
+ data_dir ||= default_data_dir
27
+ File.join(data_dir, 'kernels')
28
+ end
29
+
30
+ private
31
+
32
+ # returns %APPDATA%
33
+ def windows_user_appdata
34
+ require 'fiddle/import'
35
+ check_windows
36
+ path = Fiddle::Pointer.malloc(2 * 300) # uint16_t[300]
37
+ csidl_appdata = 0x001a
38
+ case call_SHGetFolderPathW(Fiddle::NULL, csidl_appdata, Fiddle::NULL, 0, path)
39
+ when 0
40
+ len = (1 ... (path.size/2)).find {|i| path[2*i, 2] == "\0\0" }
41
+ path = path.to_str(2*len).encode(Encoding::UTF_8, Encoding::UTF_16LE)
42
+ else
43
+ ENV.fetch('APPDATA', '')
44
+ end
45
+ end
46
+
47
+ def call_SHGetFolderPathW(hwnd, csidl, hToken, dwFlags, pszPath)
48
+ require 'fiddle/import'
49
+ shell32 = Fiddle::Handle.new('shell32')
50
+ func = Fiddle::Function.new(
51
+ shell32['SHGetFolderPathW'],
52
+ [
53
+ Fiddle::TYPE_VOIDP,
54
+ Fiddle::TYPE_INT,
55
+ Fiddle::TYPE_VOIDP,
56
+ Fiddle::TYPE_INT,
57
+ Fiddle::TYPE_VOIDP
58
+ ],
59
+ Fiddle::TYPE_INT,
60
+ Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall])
61
+ func.(hwnd, csidl, hToken, dwFlags, pszPath)
62
+ end
63
+
64
+ def check_windows
65
+ raise 'the current platform is not Windows' unless windows?
66
+ end
67
+
68
+ def windows?
69
+ /mingw|mswin/ =~ RUBY_PLATFORM
70
+ end
71
+
72
+ def apple?
73
+ /darwin/ =~ RUBY_PLATFORM
74
+ end
75
+ end
76
+ end
77
+ end