iruby 0.4.0 → 0.5.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +62 -0
  3. data/CHANGES +24 -0
  4. data/Gemfile +0 -2
  5. data/LICENSE +1 -1
  6. data/README.md +66 -62
  7. data/Rakefile +10 -10
  8. data/ci/Dockerfile.main.erb +1 -3
  9. data/iruby.gemspec +13 -19
  10. data/lib/iruby.rb +2 -6
  11. data/lib/iruby/backend.rb +19 -5
  12. data/lib/iruby/display.rb +57 -41
  13. data/lib/iruby/formatter.rb +3 -3
  14. data/lib/iruby/input.rb +6 -6
  15. data/lib/iruby/input/autoload.rb +1 -1
  16. data/lib/iruby/input/builder.rb +4 -4
  17. data/lib/iruby/input/button.rb +2 -2
  18. data/lib/iruby/input/cancel.rb +1 -1
  19. data/lib/iruby/input/checkbox.rb +3 -3
  20. data/lib/iruby/input/date.rb +3 -3
  21. data/lib/iruby/input/field.rb +2 -2
  22. data/lib/iruby/input/file.rb +3 -3
  23. data/lib/iruby/input/form.rb +6 -6
  24. data/lib/iruby/input/label.rb +4 -4
  25. data/lib/iruby/input/multiple.rb +10 -10
  26. data/lib/iruby/input/popup.rb +2 -2
  27. data/lib/iruby/input/radio.rb +6 -6
  28. data/lib/iruby/input/select.rb +8 -8
  29. data/lib/iruby/input/textarea.rb +1 -1
  30. data/lib/iruby/input/widget.rb +2 -2
  31. data/lib/iruby/jupyter.rb +1 -0
  32. data/lib/iruby/kernel.rb +18 -13
  33. data/lib/iruby/ostream.rb +22 -10
  34. data/lib/iruby/session_adapter.rb +1 -3
  35. data/lib/iruby/session_adapter/pyzmq_adapter.rb +11 -10
  36. data/lib/iruby/utils.rb +4 -0
  37. data/lib/iruby/version.rb +1 -1
  38. data/run-test.sh +1 -1
  39. data/test/helper.rb +90 -0
  40. data/test/integration_test.rb +1 -2
  41. data/test/iruby/backend_test.rb +37 -0
  42. data/test/iruby/command_test.rb +0 -1
  43. data/test/iruby/jupyter_test.rb +0 -1
  44. data/test/iruby/mime_test.rb +32 -0
  45. data/test/iruby/multi_logger_test.rb +0 -1
  46. data/test/iruby/session_adapter/cztop_adapter_test.rb +1 -1
  47. data/test/iruby/session_adapter/ffirzmq_adapter_test.rb +1 -1
  48. data/test/iruby/session_adapter/session_adapter_test_base.rb +1 -3
  49. data/test/iruby/session_adapter_test.rb +42 -67
  50. data/test/iruby/session_test.rb +9 -15
  51. data/test/run-test.rb +18 -0
  52. metadata +68 -64
  53. data/.travis.yml +0 -41
  54. data/CONTRIBUTORS +0 -19
  55. data/lib/iruby/session/rbczmq.rb +0 -72
  56. data/lib/iruby/session_adapter/rbczmq_adapter.rb +0 -33
  57. data/test/iruby/session_adapter/rbczmq_adapter_test.rb +0 -37
  58. data/test/test_helper.rb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab064a6f7df94f983b75ff53092fb54f6e9a7cc747e220a2e5b021eac840897e
4
- data.tar.gz: c20d21297d688fc7794b4d0813ada1d9762ba38ea0fb3ccd99f9fbe7845ca5e3
3
+ metadata.gz: 1576475a17c04bbdc5080fede4710cf609c9cfb1268f692e8a11653095c2902b
4
+ data.tar.gz: 46c737c267739a44dc2a7a9d4ccd5c8d3fcf89fda1b4163e74d941bd0740ec44
5
5
  SHA512:
6
- metadata.gz: eaf70e7d4ac97a11e03c7c6b5a94f5eb3d1b521ed18332ae510be5872c7faa87fb2814101fff22a8a5019adc8a93915085fb93c1fee5cfec24dd936c57c13fd4
7
- data.tar.gz: cbfb04ac1dc3be65aa4c1c83b0701e39d603a439b35119b0bfa11d11467a7e4b3d29f347317b5b2f9cdfecd17fdcaf4b1474513d56b8a730764ff1ee7482cab7
6
+ metadata.gz: 0225f7c54c11dc9668d6bbceff3dac9ba6e1d32e041355ab429b7f6b0bc204f8050f3420dfede65474614c259e7dba346db051f5414be5fb1fd2dffd9b5de894
7
+ data.tar.gz: 803cbe952a48614e1d7aeefef51f772c4420aeb07bf63a679384147fe12f10469380d733834126d206342a2c6a01d7d57d6202b8d64bd90921cd3825684d22c3
@@ -0,0 +1,62 @@
1
+ name: CI
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ test:
9
+ name: Test
10
+ runs-on: ${{ matrix.os }}
11
+
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ os:
16
+ - ubuntu-20.04
17
+ - ubuntu-latest
18
+ ruby:
19
+ - 3.0
20
+ - 2.7
21
+ - 2.6
22
+ - 2.5
23
+ - 2.4
24
+ - 2.3
25
+ - debug
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ with:
30
+ fetch-depth: 1
31
+
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+
36
+ - name: Install requirements on ubuntu
37
+ run: |
38
+ sudo apt install -y --no-install-recommends \
39
+ libczmq-dev \
40
+ python3 \
41
+ python3-pip \
42
+ python3-setuptools
43
+ sudo pip3 install wheel
44
+ sudo pip3 install -r ci/requirements.txt
45
+
46
+ - run: gem install bundler
47
+
48
+ - run: bundle install --jobs 4 --retry 3
49
+
50
+ - name: Run tests
51
+ env:
52
+ PYTHON: python3
53
+ ADAPTERS: cztop ffi-rzmq pyzmq
54
+ run: |
55
+ for adapter in $ADAPTERS; do
56
+ export IRUBY_TEST_SESSION_ADAPTER_NAME=$adapter
57
+ bundle exec rake test TESTOPTS=-v
58
+ done
59
+
60
+ - run: rake build
61
+
62
+ - run: gem install pkg/*.gem
data/CHANGES CHANGED
@@ -1,3 +1,27 @@
1
+ 0.5.0 (2021-03-25)
2
+
3
+ Bug Fixes:
4
+ * Fix Jupyter console crashes issue https://github.com/SciRuby/iruby/pull/210 (@kojix2)
5
+ * Fix syntax highlighting issue on Jpyter Lab https://github.com/SciRuby/iruby/issues/224 (@kojix2)
6
+ * Fix interoperability issue with ruby-git https://github.com/SciRuby/iruby/pull/139 (@habemus-papadum)
7
+ * Fix the issue of `$stderr.write` that cannot handle multiple arguments https://github.com/SciRuby/iruby/issues/206 (@kojix2)
8
+ * Remove a buggy `inspect_request` implementation https://github.com/SciRuby/iruby/pull/119 (@LunarLanding)
9
+ * Fix uninitialized constant `Fiddle` caused in initialization phase https://github.com/SciRuby/iruby/issues/264 (@MatthewSteen, @kjoix2)
10
+ * Fix the issue on displaying a table https://github.com/SciRuby/iruby/pull/281 (@ankane)
11
+
12
+ Enhancements:
13
+ * Add `IRuby.clear_output` method https://github.com/SciRuby/iruby/pull/220 (@kojix2)
14
+ * Make backtrace on exception simplify and more appropriate for code in a cell https://github.com/SciRuby/iruby/pull/249 (@zheng-yongping)
15
+ * Make syntax error message more appropriate https://github.com/SciRuby/iruby/pull/251 (@zheng-yongping)
16
+ * Remove top-level `In` and `Out` constants https://github.com/SciRuby/iruby/pull/229 (@kojix2)
17
+ * Use text/plain for the default format of `Numo::NArray` objects https://github.com/SciRuby/iruby/pull/255 (@kojix2)
18
+ * Use ffi-rzmq as the default ZeroMQ adapter https://github.com/SciRuby/iruby/pull/256 (@kojix2)
19
+ * Drop rbczmq support https://github.com/SciRuby/iruby/pull/260 (@rstammer)
20
+ * Add ruby-vips image support https://github.com/SciRuby/iruby/pull/279 (@ankane)
21
+ * Replace mimemagic with mime-types https://github.com/SciRuby/iruby/pull/291 (@mrkn)
22
+
23
+ 0.4.0 (2019-07-31)
24
+
1
25
  0.3 (2017-03-26)
2
26
 
3
27
  Bug Fixes:
data/Gemfile CHANGED
@@ -10,10 +10,8 @@ end
10
10
  group :plot do
11
11
  gem 'gnuplot'
12
12
  gem 'rubyvis'
13
- gem 'nyaplot', github: 'sciruby/nyaplot'
14
13
  end
15
14
 
16
15
  group :test do
17
16
  gem 'cztop'
18
- gem 'rbczmq'
19
17
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2015 IRuby contributors and the Ruby Science Foundation
1
+ Copyright (c) 2013 - present IRuby contributors and the Ruby Science Foundation
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,52 +1,80 @@
1
1
  # IRuby
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/iruby.svg)](https://badge.fury.io/rb/iruby)
4
- [![Build Status](https://travis-ci.org/SciRuby/iruby.svg?branch=master)](https://travis-ci.org/SciRuby/iruby)
4
+ [![Build Status](https://github.com/SciRuby/iruby/workflows/CI/badge.svg)](https://github.com/SciRuby/iruby/actions)
5
5
  [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/RubyData/binder/master?filepath=ruby-data.ipynb)
6
6
 
7
7
  IRuby is a Ruby kernel for [Jupyter project](http://try.jupyter.org/).
8
8
 
9
+ ## Try IRuby
10
+
11
+ You can try IRuby with a sample notebook on Binder (the same link as the banner placed above):
12
+
13
+ https://mybinder.org/v2/gh/RubyData/binder/master?filepath=ruby-data.ipynb
14
+
15
+ The following URL launches JupyterLab directly on Binder.
16
+
17
+ https://mybinder.org/v2/gh/RubyData/binder/master?filepath=../lab
18
+
9
19
  ## Installation
10
- How to set up [ZeroMQ](http://zeromq.org/) depends on your environment.
11
- You can use one of the following libraries.
12
- * [CZTop](https://gitlab.com/paddor/cztop) and [CZMQ](https://github.com/zeromq/czmq) >= 4.0.0
13
- * [ffi-rzmq](https://github.com/chuckremes/ffi-rzmq) and [libzmq
14
- ](https://github.com/zeromq/libzmq) >= 3.2
15
20
 
16
- ### Ubuntu
17
- Install Jupyter with [Anaconda](https://www.anaconda.com/) (recommended).
21
+ ### Requirements
18
22
 
19
- #### Setup ZeroMQ on Ubuntu 16.04
20
- CZTop requires CZMQ >= 4.0.0 and ZMQ >= 4.2.0. The official packages for Ubuntu 16.04 don't satisfy these version requrements, so you need to install from source.
23
+ * [Jupyter](https://jupyter.org)
24
+ * One of the following is required
25
+ * [ffi-rzmq](https://github.com/chuckremes/ffi-rzmq) and [libzmq](https://github.com/zeromq/libzmq)
26
+ * [CZTop](https://gitlab.com/paddor/cztop) and [CZMQ](https://github.com/zeromq/czmq)
27
+
28
+ If both ffi-rzmq and cztop are installed, ffi-rzmq is used. If you prefer cztop, set the following environment variable.
29
+
30
+ ```sh
31
+ export IRUBY_SESSION_ADAPTER="cztop"
32
+ ```
33
+
34
+ * We recommend the [Pry](https://github.com/pry/pry) backend for full functionality.
35
+ * If you want to install the latest version of IRuby from the source code, try [specific_install](https://github.com/rdp/specific_install).
21
36
 
22
- ```shell
23
- sudo apt install libtool libffi-dev ruby ruby-dev make
24
- sudo apt install git libzmq-dev autoconf pkg-config
25
- git clone https://github.com/zeromq/czmq
26
- cd czmq
27
- ./autogen.sh && ./configure && sudo make && sudo make install
28
37
  ```
38
+ gem specific_install https://github.com/SciRuby/iruby
39
+ ```
40
+
41
+ ### Ubuntu
29
42
 
30
- #### Setup ZeroMQ on Ubuntu 17.04 to 18.10
31
- Use official packages.
43
+ Install Jupyter.
44
+
45
+ #### Ubuntu 17+
32
46
 
33
47
  ```shell
34
48
  sudo apt install libtool libffi-dev ruby ruby-dev make
35
49
  sudo apt install libzmq3-dev libczmq-dev
50
+
51
+ gem install ffi-rzmq
52
+ gem install iruby --pre
53
+ iruby register --force
36
54
  ```
37
55
 
38
- #### Install CZTop and IRuby
56
+ #### Ubuntu 16
57
+
58
+ CZTop requires CZMQ >= 4.0.0 and ZMQ >= 4.2.0. The official packages for Ubuntu 16.04 don't satisfy these version requrements, so you need to install from source.
59
+
39
60
  ```shell
61
+ sudo apt install libtool libffi-dev ruby ruby-dev make
62
+ sudo apt install git libzmq-dev autoconf pkg-config
63
+ git clone https://github.com/zeromq/czmq
64
+ cd czmq
65
+ ./autogen.sh && ./configure && sudo make && sudo make install
66
+
40
67
  gem install cztop
41
68
  gem install iruby --pre
42
69
  iruby register --force
43
70
  ```
44
71
 
45
72
  ### Windows
46
- Install git and Jupyter with [Anaconda](https://www.anaconda.com/) (recommended).
73
+
74
+ Install git and Jupyter.
47
75
  [DevKit](https://rubyinstaller.org/add-ons/devkit.html) is necessary for building RubyGems with native C-based extensions.
48
76
 
49
- Install ZeroMQ.
77
+ Install ZeroMQ.
50
78
  ```shell
51
79
  pacman -S mingw64/mingw-w64-x86_64-zeromq
52
80
  ```
@@ -58,10 +86,12 @@ iruby register --force
58
86
  ```
59
87
 
60
88
  ### macOS
89
+
61
90
  Install ruby with rbenv or rvm.
62
- Install Jupyter with [Anaconda](https://www.anaconda.com/) (recommended).
91
+ Install Jupyter.
63
92
 
64
93
  #### Homebrew
94
+
65
95
  ```shell
66
96
  brew install automake gmp libtool wget
67
97
  brew install zeromq --HEAD
@@ -78,6 +108,7 @@ iruby register --force
78
108
  ```
79
109
 
80
110
  #### MacPorts
111
+
81
112
  If you are using macports, run the following commands.
82
113
 
83
114
  ```shell
@@ -86,47 +117,18 @@ gem install ffi-rzmq
86
117
  gem install iruby
87
118
  ```
88
119
 
89
- ### FreeBSD
90
- At first install IPython/Jupyter.
91
- There is a pyzmq ports (ports/net/py-pyzmq) which depends on libzmq4, however, it doesn't works with ipython.
92
- Therefore we use libzmq3 like the following:
120
+ ### Docker
93
121
 
94
- 1. make your ports tree up-to-date.
95
- 2. replace LIBDEPENDS line in ports/net/py-pyzmq/Makefile
122
+ Try [RubyData Docker Stacks](https://github.com/RubyData/docker-stacks).
123
+ Running jupyter notebook:
96
124
 
97
125
  ```shell
98
- LIB_DEPENDS= libzmq.so:${PORTSDIR}/net/libzmq4
99
- ```
100
- with
101
- ```shell
102
- LIB_DEPENDS= libzmq.so:${PORTSDIR}/net/libzmq3
103
- ```
104
- 3. install related packages
105
-
106
- ```shell
107
- sudo pkg install libzmq3 py27-qt4-gui py27-pexpect-3.3 py27-qt4-svg py27-pygments py27-Jinja2 py27-tornado py27-jsonschema
108
- ```
109
- 4. make install using ports
110
-
111
- ```shell
112
- cd /usr/ports/net/py-pyzmq
113
- sudo make install
114
- cd /usr/ports/devel/ipython
115
- sudo make install
116
- ```
117
- Then, install IRuby and related ports and gems.
118
- ```shell
119
- sudo pkg install rubygem-mimemagic
120
- sudo gem install ffi-rzmq # install ffi, ffi-rzmq-core and ffi-rzmq
121
- git clone https://github.com/SciRuby/iruby.git
122
- cd iruby
123
- gem build iruby.gemspec
124
- sudo gem install iruby-0.2.7.gem
126
+ docker run -p 8888:8888 rubydata/datascience-notebook
125
127
  ```
126
128
 
127
129
  ### Installation for JRuby
128
130
 
129
- You can use Java classes in your IRuby notebook.
131
+ You can use Java classes in your IRuby notebook.
130
132
 
131
133
  * JRuby version >= 9.0.4.0
132
134
  * cztop gem
@@ -147,19 +149,21 @@ $ iruby register --force
147
149
  ```
148
150
 
149
151
  ## Notebooks
152
+
150
153
  Take a look at the [example notebook](http://nbviewer.ipython.org/urls/raw.github.com/SciRuby/sciruby-notebooks/master/getting_started.ipynb)
151
154
  and the [collection of notebooks](https://github.com/SciRuby/sciruby-notebooks/) which includes a Dockerfile to create a containerized installation of iruby
152
155
  and other scientific gems. You can find the prebuild image at [dockerhub](https://registry.hub.docker.com/u/minad/sciruby-notebooks/).
153
156
 
154
157
  ## Contributing
155
- We welcome contributions from everyone.
156
158
 
157
- ## Authors
158
- See the [CONTRIBUTORS](CONTRIBUTORS) file.
159
+ Contributions to IRuby are very welcome.
160
+
161
+ To former contributors
162
+
163
+ In February 2021, [IRuby became the canonical repository](https://github.com/SciRuby/iruby/issues/285) and is no longer a fork from [minrk/iruby](https://github.com/minrk/iruby). Please fork from this repository again before making pull requests.
159
164
 
160
165
  ## License
161
- Copyright © 2013-19, IRuby contributors and the Ruby Science Foundation.
162
166
 
163
- All rights reserved.
167
+ Copyright (c) IRuby contributors and the Ruby Science Foundation.
164
168
 
165
- IRuby, along with [SciRuby](http://sciruby.com/), is licensed under the MIT license. See the [LICENSE](LICENSE) file.
169
+ Licensed under the [MIT](LICENSE) license.
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
- require 'rake/testtask'
1
+ require "bundler/gem_helper"
2
2
 
3
- begin
4
- require 'bundler/gem_tasks'
5
- rescue Exception
6
- end
3
+ base_dir = File.join(File.dirname(__FILE__))
4
+
5
+ helper = Bundler::GemHelper.new(base_dir)
6
+ helper.install
7
7
 
8
8
  FileList['tasks/**.rake'].each {|f| load f }
9
9
 
10
- Rake::TestTask.new('test') do |t|
11
- t.libs << 'lib'
12
- t.libs << 'test'
13
- t.test_files = FileList['test/**/*_test.rb']
14
- t.verbose = true
10
+ desc "Run tests"
11
+ task :test do
12
+ cd(base_dir) do
13
+ ruby("test/run-test.rb")
14
+ end
15
15
  end
16
16
 
17
17
  task default: 'test'
@@ -1,8 +1,6 @@
1
1
  FROM iruby-test-base:ruby-<%= ruby_version %>
2
2
 
3
- RUN gem install cztop \
4
- && gem install rbczmq -- --with-system-libs
5
-
3
+ RUN gem install cztop
6
4
  RUN mkdir -p /iruby
7
5
  ADD . /iruby
8
6
  WORKDIR /iruby
data/iruby.gemspec CHANGED
@@ -1,36 +1,30 @@
1
- # coding: utf-8
2
1
  require_relative 'lib/iruby/version'
3
- require 'date'
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = 'iruby'
7
- s.date = Date.today.to_s
8
5
  s.version = IRuby::VERSION
9
6
  s.authors = ['Daniel Mendler', 'The SciRuby developers']
10
7
  s.email = ['mail@daniel-mendler.de']
11
- s.summary = 'Ruby Kernel for Jupyter/IPython'
12
- s.description = 'A Ruby kernel for Jupyter/IPython frontends (e.g. notebook). Try it at try.jupyter.org.'
8
+ s.summary = 'Ruby Kernel for Jupyter'
9
+ s.description = 'A Ruby kernel for Jupyter environment. Try it at try.jupyter.org.'
13
10
  s.homepage = 'https://github.com/SciRuby/iruby'
14
11
  s.license = 'MIT'
15
12
 
16
- s.files = `git ls-files`.split($/)
13
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
14
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
15
  s.test_files = s.files.grep(%r{^test/})
19
- s.require_paths = %w(lib)
16
+ s.require_paths = %w[lib]
20
17
 
21
- m = "Consider installing the optional dependencies to get additional functionality:\n"
22
- File.read('Gemfile').scan(/gem\s+'(.*?)'/) { m << " * #{$1}\n" }
23
- s.post_install_message = m << "\n"
18
+ s.required_ruby_version = '>= 2.3.0'
24
19
 
25
- s.required_ruby_version = '>= 2.1.0'
20
+ s.add_dependency 'bond', '~> 0.5'
21
+ s.add_dependency 'data_uri', '~> 0.1'
22
+ s.add_dependency 'ffi-rzmq'
23
+ s.add_dependency 'mime-types', '>= 3.3.1'
24
+ s.add_dependency 'multi_json', '~> 1.11'
26
25
 
27
- s.add_development_dependency 'rake'
28
- s.add_development_dependency 'minitest'
29
- s.add_development_dependency 'ffi-rzmq'
30
26
  s.add_development_dependency 'pycall', '>= 1.2.1'
31
-
32
- s.add_runtime_dependency 'bond', '~> 0.5'
33
- s.add_runtime_dependency 'multi_json', '~> 1.11'
34
- s.add_runtime_dependency 'mimemagic', '~> 0.3'
35
- s.add_runtime_dependency 'data_uri', '~> 0.1'
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'test-unit'
29
+ s.add_development_dependency 'test-unit-rr'
36
30
  end
data/lib/iruby.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'mimemagic'
1
+ require 'mime/types'
2
2
  require 'multi_json'
3
3
  require 'securerandom'
4
4
  require 'openssl'
@@ -24,11 +24,7 @@ if ENV.fetch('IRUBY_OLD_SESSION', false)
24
24
  begin
25
25
  require 'iruby/session/cztop'
26
26
  rescue LoadError
27
- begin
28
- require 'iruby/session/rbczmq'
29
- rescue LoadError
30
- STDERR.puts "You should install ffi-rzmq, cztop, or rbczmq before running iruby notebook. See README."
31
- end
27
+ STDERR.puts "Please install ffi-rzmq or cztop before running iruby. See README."
32
28
  end
33
29
  end
34
30
  else
data/lib/iruby/backend.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module IRuby
2
2
  In, Out = [nil], [nil]
3
- ::In, ::Out = In, Out
4
3
 
5
4
  module History
6
5
  def eval(code, store_history)
@@ -33,15 +32,17 @@ module IRuby
33
32
  end
34
33
 
35
34
  class PlainBackend
35
+ attr_reader :eval_path
36
36
  prepend History
37
37
 
38
38
  def initialize
39
39
  require 'bond'
40
40
  Bond.start(debug: true)
41
+ @eval_path = '(iruby)'
41
42
  end
42
43
 
43
44
  def eval(code, store_history)
44
- TOPLEVEL_BINDING.eval(code)
45
+ TOPLEVEL_BINDING.eval(code, @eval_path, 1)
45
46
  end
46
47
 
47
48
  def complete(code)
@@ -50,28 +51,41 @@ module IRuby
50
51
  end
51
52
 
52
53
  class PryBackend
54
+ attr_reader :eval_path
53
55
  prepend History
54
56
 
55
57
  def initialize
56
58
  require 'pry'
57
- Pry.memory_size = 3
59
+ Pry.memory_size = 3
58
60
  Pry.pager = false # Don't use the pager
59
61
  Pry.print = proc {|output, value|} # No result printing
60
62
  Pry.exception_handler = proc {|output, exception, _| }
63
+ @eval_path = Pry.eval_path
61
64
  reset
62
65
  end
63
66
 
64
67
  def eval(code, store_history)
68
+ Pry.current_line = 1
65
69
  @pry.last_result = nil
66
70
  unless @pry.eval(code)
67
71
  reset
68
72
  raise SystemExit
69
73
  end
70
- unless @pry.eval_string.empty?
74
+
75
+ # Pry::Code.complete_expression? return false
76
+ if !@pry.eval_string.empty?
71
77
  syntax_error = @pry.eval_string
72
78
  @pry.reset_eval_string
73
- @pry.evaluate_ruby syntax_error
79
+ @pry.evaluate_ruby(syntax_error)
80
+
81
+ # Pry::Code.complete_expression? raise SyntaxError
82
+ # evaluate again for current line number
83
+ elsif @pry.last_result_is_exception? &&
84
+ @pry.last_exception.is_a?(SyntaxError) &&
85
+ @pry.last_exception.is_a?(Pry::UserError)
86
+ @pry.evaluate_ruby(code)
74
87
  end
88
+
75
89
  raise @pry.last_exception if @pry.last_result_is_exception?
76
90
  @pry.push_initial_binding unless @pry.current_binding # ensure that we have a binding
77
91
  @pry.last_result