iruby 0.1.13 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require 'logger'
2
+
3
+ module IRuby
4
+ class << self
5
+ attr_accessor :logger
6
+ end
7
+
8
+ class MultiLogger < BasicObject
9
+ def initialize(*loggers)
10
+ @loggers = loggers
11
+ end
12
+
13
+ def method_missing(name, *args, &b)
14
+ @loggers.map {|x| x.respond_to?(name) && x.public_send(name, *args, &b) }.any?
15
+ end
16
+ end
17
+ end
data/lib/iruby/ostream.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  module IRuby
2
2
  # IO-like object that publishes to 0MQ socket.
3
3
  class OStream
4
- def initialize(session, socket, name)
5
- @session = session
6
- @socket = socket
7
- @name = name
4
+ attr_accessor :sync
5
+
6
+ def initialize(session, name)
7
+ @session, @name = session, name
8
8
  end
9
9
 
10
10
  def close
11
- @socket = nil
11
+ @session = nil
12
12
  end
13
13
 
14
14
  def flush
@@ -26,15 +26,17 @@ module IRuby
26
26
  alias_method :readline, :read
27
27
 
28
28
  def write(s)
29
- raise 'I/O operation on closed file' unless @socket
30
- @session.send(@socket, 'stream', { name: @name, data: s.to_s })
29
+ raise 'I/O operation on closed file' unless @session
30
+ @session.send(:publish, 'stream', { name: @name, text: s.to_s })
31
31
  nil
32
32
  end
33
33
  alias_method :<<, :write
34
34
  alias_method :print, :write
35
35
 
36
- def puts(s)
37
- write "#{s}\n"
36
+ def puts(*lines)
37
+ lines = [''] if lines.empty?
38
+ lines.each { |s| write("#{s}\n")}
39
+ nil
38
40
  end
39
41
 
40
42
  def writelines(lines)
data/lib/iruby/session.rb CHANGED
@@ -2,8 +2,9 @@ module IRuby
2
2
  class Session
3
3
  DELIM = '<IDS|MSG>'
4
4
 
5
- def initialize(username, config)
5
+ def initialize(username, config, sockets)
6
6
  @username = username
7
+ @sockets = sockets
7
8
  @session = SecureRandom.uuid
8
9
  @msg_id = 0
9
10
  if config['key'] && config['signature_scheme']
@@ -18,32 +19,17 @@ module IRuby
18
19
  msg_type: type,
19
20
  msg_id: @msg_id,
20
21
  username: @username,
21
- session: @session
22
+ session: @session,
23
+ version: '5.0'
22
24
  }
23
25
  @msg_id += 1
24
26
 
25
- list = serialize(header, content, ident)
26
- list.each_with_index do |part, i|
27
- socket.send_string(part, i == list.size - 1 ? 0 : ZMQ::SNDMORE)
28
- end
27
+ @sockets[socket].send_message(serialize(header, content, ident))
29
28
  end
30
29
 
31
30
  # Receive a message and decode it
32
- def recv(socket, mode)
33
- msg = []
34
- while msg.empty? || socket.more_parts?
35
- begin
36
- frame = ''
37
- rc = socket.recv_string(frame, mode)
38
- ZMQ::Util.error_check('zmq_msg_send', rc)
39
- msg << frame
40
- rescue
41
- end
42
- end
43
-
44
- i = msg.index(DELIM)
45
- idents, msg_list = msg[0..i-1], msg[i+1..-1]
46
- msg = unserialize(msg_list)
31
+ def recv(socket)
32
+ idents, msg = unserialize(@sockets[socket].recv_message)
47
33
  @last_received_header = msg[:header]
48
34
  return idents, msg
49
35
  end
@@ -55,15 +41,26 @@ module IRuby
55
41
  MultiJson.dump(@last_received_header || {}),
56
42
  '{}',
57
43
  MultiJson.dump(content || {})]
58
- ([ident].flatten.compact << DELIM << sign(msg)) + msg
44
+ #STDERR.puts "SEND #{(([ident].flatten.compact << DELIM << sign(msg)) + msg).inspect}"
45
+ ZMQ::Message(*(([ident].flatten.compact << DELIM << sign(msg)) + msg))
59
46
  end
60
47
 
61
- def unserialize(msg_list)
48
+ def unserialize(msg)
49
+ raise 'no message received' unless msg
50
+ parts = []
51
+ while frame = msg.popstr
52
+ parts << frame
53
+ end
54
+ #STDERR.puts "RECV #{parts.inspect}"
55
+
56
+ i = parts.index(DELIM)
57
+ idents, msg_list = parts[0..i-1], parts[i+1..-1]
58
+
62
59
  minlen = 5
63
60
  raise 'malformed message, must have at least #{minlen} elements' unless msg_list.length >= minlen
64
61
  s, header, parent_header, metadata, content, buffers = *msg_list
65
62
  raise 'Invalid signature' unless s == sign(msg_list[1..-1])
66
- {
63
+ return idents, {
67
64
  header: MultiJson.load(header),
68
65
  parent_header: MultiJson.load(parent_header),
69
66
  metadata: MultiJson.load(metadata),
data/lib/iruby/utils.rb CHANGED
@@ -4,10 +4,10 @@ module IRuby
4
4
  end
5
5
 
6
6
  def self.display(obj, options = {})
7
- Kernel.instance.display(obj, options)
7
+ Kernel.instance.session.send(:publish, 'display_data', data: Display.display(obj, options), metadata: {}) unless obj.nil?
8
8
  end
9
9
 
10
- def self.table(s, options = {})
10
+ def self.table(s, **options)
11
11
  html(HTML.table(s, options))
12
12
  end
13
13
 
data/lib/iruby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IRuby
2
- VERSION = '0.1.13'
2
+ VERSION = '0.2.0'
3
3
  end
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+ require 'open3'
3
+ require 'expect'
4
+
5
+ class IntegrationTest < IRubyTest
6
+ def setup
7
+ @stdin, @stdout, @stderr, @process = Open3.popen3('bin/iruby')
8
+ expect 'In [', 30
9
+ expect '1'
10
+ expect ']:'
11
+ end
12
+
13
+ def teardown
14
+ @stdin.close
15
+ @stdout.close
16
+ @stderr.close
17
+ @process.kill
18
+ end
19
+
20
+ def write(input)
21
+ @stdin.puts input
22
+ end
23
+
24
+ def expect(pattern, timeout = 1)
25
+ assert @stdout.expect(pattern, timeout), "#{pattern} expected"
26
+ end
27
+
28
+ def test_interaction
29
+ write '"Hello, world!"'
30
+ expect '"Hello, world!"'
31
+
32
+ write 'puts "Hello!"'
33
+ expect 'Hello!'
34
+
35
+ write '12 + 12'
36
+ expect '24'
37
+
38
+ write 'ls'
39
+ expect 'self.methods'
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ require 'stringio'
2
+ require 'test_helper'
3
+ require 'iruby/logger'
4
+
5
+ class MultiLoggerTest < IRubyTest
6
+ def test_multilogger
7
+ out, err = StringIO.new, StringIO.new
8
+ logger = IRuby::MultiLogger.new(Logger.new(out), Logger.new(err))
9
+ logger.warn 'You did a bad thing'
10
+ assert_match 'WARN', out.string
11
+ assert_match 'WARN', err.string
12
+ assert_match 'bad thing', out.string
13
+ assert_match 'bad thing', err.string
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'iruby'
2
+ require 'minitest/autorun'
3
+
4
+ class IRubyTest < Minitest::Test
5
+ end
metadata CHANGED
@@ -1,104 +1,116 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Damián Silvani
8
- - Min RK
9
- - Martin Sarsale
10
- - Josh Adams
11
7
  - Daniel Mendler
8
+ - The SciRuby developers
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
- date: 2014-08-19 00:00:00.000000000 Z
12
+ date: 2015-05-25 00:00:00.000000000 Z
16
13
  dependencies:
17
14
  - !ruby/object:Gem::Dependency
18
15
  name: rake
19
16
  requirement: !ruby/object:Gem::Requirement
20
17
  requirements:
21
- - - ">="
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '10.4'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
22
26
  - !ruby/object:Gem::Version
23
- version: '0'
27
+ version: '10.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: minitest
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.6'
24
35
  type: :development
25
36
  prerelease: false
26
37
  version_requirements: !ruby/object:Gem::Requirement
27
38
  requirements:
28
- - - ">="
39
+ - - "~>"
29
40
  - !ruby/object:Gem::Version
30
- version: '0'
41
+ version: '5.6'
31
42
  - !ruby/object:Gem::Dependency
32
43
  name: bond
33
44
  requirement: !ruby/object:Gem::Requirement
34
45
  requirements:
35
46
  - - "~>"
36
47
  - !ruby/object:Gem::Version
37
- version: 0.5.0
48
+ version: '0.5'
38
49
  type: :runtime
39
50
  prerelease: false
40
51
  version_requirements: !ruby/object:Gem::Requirement
41
52
  requirements:
42
53
  - - "~>"
43
54
  - !ruby/object:Gem::Version
44
- version: 0.5.0
55
+ version: '0.5'
45
56
  - !ruby/object:Gem::Dependency
46
- name: ffi-rzmq
57
+ name: rbczmq
47
58
  requirement: !ruby/object:Gem::Requirement
48
59
  requirements:
49
60
  - - "~>"
50
61
  - !ruby/object:Gem::Version
51
- version: '2.0'
62
+ version: '1.7'
52
63
  type: :runtime
53
64
  prerelease: false
54
65
  version_requirements: !ruby/object:Gem::Requirement
55
66
  requirements:
56
67
  - - "~>"
57
68
  - !ruby/object:Gem::Version
58
- version: '2.0'
69
+ version: '1.7'
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: multi_json
61
72
  requirement: !ruby/object:Gem::Requirement
62
73
  requirements:
63
74
  - - "~>"
64
75
  - !ruby/object:Gem::Version
65
- version: 1.10.0
76
+ version: '1.11'
66
77
  type: :runtime
67
78
  prerelease: false
68
79
  version_requirements: !ruby/object:Gem::Requirement
69
80
  requirements:
70
81
  - - "~>"
71
82
  - !ruby/object:Gem::Version
72
- version: 1.10.0
83
+ version: '1.11'
73
84
  - !ruby/object:Gem::Dependency
74
85
  name: mimemagic
75
86
  requirement: !ruby/object:Gem::Requirement
76
87
  requirements:
77
88
  - - "~>"
78
89
  - !ruby/object:Gem::Version
79
- version: 0.2.0
90
+ version: '0.3'
80
91
  type: :runtime
81
92
  prerelease: false
82
93
  version_requirements: !ruby/object:Gem::Requirement
83
94
  requirements:
84
95
  - - "~>"
85
96
  - !ruby/object:Gem::Version
86
- version: 0.2.0
97
+ version: '0.3'
87
98
  description: Ruby Kernel for IPython
88
99
  email:
89
- - benjaminrk@gmail.com
100
+ - mail@daniel-mendler.de
90
101
  executables:
91
102
  - iruby
92
103
  extensions: []
93
104
  extra_rdoc_files: []
94
105
  files:
95
106
  - ".gitignore"
107
+ - ".travis.yml"
96
108
  - CHANGES
97
109
  - CONTRIBUTORS
98
110
  - Gemfile
99
111
  - IRuby-Example.ipynb
100
- - LICENSE
101
- - README.md
112
+ - LICENSE.txt
113
+ - README.rdoc
102
114
  - Rakefile
103
115
  - bin/iruby
104
116
  - examples/display.ipynb
@@ -107,22 +119,25 @@ files:
107
119
  - iruby.gemspec
108
120
  - lib/iruby.rb
109
121
  - lib/iruby/backend.rb
122
+ - lib/iruby/comm.rb
110
123
  - lib/iruby/command.rb
111
124
  - lib/iruby/display.rb
112
125
  - lib/iruby/formatter.rb
113
126
  - lib/iruby/kernel.rb
127
+ - lib/iruby/logger.rb
114
128
  - lib/iruby/ostream.rb
115
129
  - lib/iruby/session.rb
116
- - lib/iruby/static/base/images/favicon.ico
117
- - lib/iruby/static/base/images/ipynblogo.png
118
- - lib/iruby/static/base/images/src/ipynblogo.svg
119
- - lib/iruby/static/base/images/src/ruby.svg
120
- - lib/iruby/static/custom/custom.css
121
- - lib/iruby/static/custom/custom.js
122
130
  - lib/iruby/utils.rb
123
131
  - lib/iruby/version.rb
132
+ - logo/favicon.ico
133
+ - logo/iruby.png
134
+ - logo/iruby.svg
135
+ - logo/ruby.svg
124
136
  - screenshot.png
125
- homepage: https://github.com/minad/iruby
137
+ - test/integration_test.rb
138
+ - test/iruby/multi_logger_test.rb
139
+ - test/test_helper.rb
140
+ homepage: https://github.com/SciRuby/iruby
126
141
  licenses:
127
142
  - MIT
128
143
  metadata: {}
@@ -131,13 +146,10 @@ post_install_message: |+
131
146
  * pry
132
147
  * pry-doc
133
148
  * pry-theme
134
- * pry-syntax-hacks
135
- * pry-git
136
149
  * awesome_print
137
- * gruff
138
- * rmagick
139
150
  * gnuplot
140
151
  * rubyvis
152
+ * nyaplot
141
153
 
142
154
  rdoc_options: []
143
155
  require_paths:
@@ -146,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
158
  requirements:
147
159
  - - ">="
148
160
  - !ruby/object:Gem::Version
149
- version: '0'
161
+ version: 2.0.0
150
162
  required_rubygems_version: !ruby/object:Gem::Requirement
151
163
  requirements:
152
164
  - - ">="
@@ -158,4 +170,8 @@ rubygems_version: 2.2.2
158
170
  signing_key:
159
171
  specification_version: 4
160
172
  summary: A Ruby kernel for IPython frontends (notebook console, etc.)
161
- test_files: []
173
+ test_files:
174
+ - test/integration_test.rb
175
+ - test/iruby/multi_logger_test.rb
176
+ - test/test_helper.rb
177
+ has_rdoc:
data/README.md DELETED
@@ -1,24 +0,0 @@
1
- # IRuby
2
-
3
- This is a Ruby kernel for IPython.
4
-
5
- ![IRuby Notebook](screenshot.png)
6
-
7
- ### Quick start
8
-
9
- At first install the packages `ipython`, `python-jinja`, `python-tornado`, `python-pyzmq` so that you get a working `ipython notebook`.
10
- Maybe the packages are called slightly different on your Unix.
11
-
12
- Now install the rubygem using `gem install iruby` and then run `iruby notebook` or `iruby`.
13
-
14
- Take a look at the [Example Notebook](http://nbviewer.ipython.org/urls/raw.github.com/minad/iruby/master/IRuby-Example.ipynb).
15
-
16
- The IRuby notebook requires `ipython` >= 1.2.0. Furthermore we need `libzmq` >= 3.2 to work. Version 2.2.0 will not work. If you're using an old Debian without a new enough version of `libzmq`, you can install [Anaconda](https://store.continuum.io/), a Python distribution with newer versions.
17
-
18
- ### Authors
19
-
20
- See the [CONTRIBUTORS](CONTRIBUTORS) file.
21
-
22
- ### License
23
-
24
- See the [LICENSE](LICENSE) file.