Commit 0decb793 authored by Gordon Ball's avatar Gordon Ball

New upstream version 0.3

parents
.ipynb_checkpoints/
*.gem
*.rbc
*.log
.bundle
.config
.yardoc
Gemfile.lock
coverage
doc/
pkg
rdoc
test/tmp
test/version_tmp
tmp
venv
language: ruby
rvm:
- ruby-head
- 2.2.2
- 2.1.6
- 2.0.0
before_install:
- "sudo apt-get install libzmq3-dev"
- "sudo pip install 'ipython[notebook]'"
script: bundle exec rake
notifications:
irc: "chat.freenode.net#sciruby"
\ No newline at end of file
0.3 (2017-03-26)
Bug Fixes:
* Disable Jupyter keyboard manager for all popups made using IRuby.popup (@kylekyle).
* Fix Iruby/Input date values bug that set date fields to whatever the last date value was (@kylekyle).
* Fix a bug where time strings put into prompter would give an 'out of range' error (@kylekyle).
Enhancements:
* Improvements to IRuby dependency detection using `Bundler::Dependencies#specs` (@kou).
* Use less memory forcing pry to store only the last 3 commands in memory (@kylekyle).
* Use bigger z-index that is used accross all browsers (@kylekyle).
* Ability to input date values as DateTime objects in IRuby/Input (@kylekyle).
* Add option to have check boxes checked by default (@kylekyle).
* Option for multi-select in drop down menus in the prompter (@kylekyle).
* Add support for multiple widgets using `IRuby::Input::Multiple` (@kylekyle).
* Calender icon for date selector icon (@kylekyle).
* Add support for Numo/NArray (@zalt50).
* Text now only completes after a space (@zalt50).
* Remove the DONTWAIT flag when receiving a message (@cloud-oak).
* Add support for CZTop (@kou).
0.2.9 (2016-05-02)
Bug Fixes:
* Fix an error where a NoMethodError was being raised where a table rendered using an Array of Hashes has more than `maxcols` columns. (@CGamesPlay)
* Patch PryBackend to throw unterminated string and unexpected end-of-file syntax errors (@kylekyle)
Enhnacements:
* Add an IRuby::Input class which provides widgets for getting inputs from users. (@kylekyle)
* Add data_uri dependency (@kylekyle)
* Added a clear_output display function (@mrkn)
* Doc fixes for installation (@kozo2, @generall)
0.2.8 (2015-12-06)
* Add compatibility with ffi-rzmq
* Windows support
0.2.7 (2015-07-02)
* Fix problem with autoloaded constants in Display, problem with sciruby gem
0.2.6 (2015-06-21)
* Check registered kernel and Gemfile to prevent gem loading problems
* Support to_tex method for the rendering
0.2.5 (2015-06-07)
* Fix #29, empty signatures
* Move iruby utils to IRuby::Utils module
* Add IRuby.tex alias for IRuby.latex
* Remove example notebooks from gem
0.2.4 (2015-06-02)
* Better exception handling
* Fix ctrl-C issue #17
* Fix timeout issue #19
0.2.3 (2015-05-31)
* Fix notebook indentation
* Fix tab completion for multiple lines
0.2.2 (2015-05-26)
* Support history variables In, Out, _, _i etc
* Internal refactoring and minor bugfixes
0.2.1 (2015-05-26)
* Copy Ruby logo to kernel specification
0.2.0 (2015-05-25)
* Dropped IPython2 support
* Dropped Ruby < 2.0.0 support
* Supports and requires now IPython3/Jupyter
* Switch from ffi-rzmq to rbczmq
* Added IRuby::Conn (experimental, to be used by widgets)
* iruby register/unregister commands to register IRuby kernel in Jupyter
0.1.13 (2014-08-19)
* Improved IRuby.table, supports :maxrows and :maxcols
* IRuby#javascript workaround (https://github.com/ipython/ipython/issues/6259)
0.1.12 (2014-08-01)
* IRuby#table add option maxrows
* powerful display system with format and datatype registry, see #25
* Add IRuby#javascript
* Add IRuby#svg
0.1.11 (2014-07-08)
* Push binding if pry binding stack is empty
0.1.10 (2014-07-08)
* Fix #19 (pp)
* Handle exception when symlink cannot be created
* Fix dependencies and Pry backend
0.1.9 (2014-02-28)
* Check IPython version
0.1.7/0.1.8
* Bugfixes #11, #12, #13
0.1.6 (2013-10-11)
* Print Matrix and GSL::Matrix as LaTeX
* Add check for Pry version
0.1.5 (2013-10-03)
* Implement a rich display system
* Fix error output
0.1.4 (2013-10-03)
* Extract display handler from kernel
* Always return a text/plain response
0.1.3 (2013-10-03)
* Implement missing request handlers
* Detect if Bundler is running and set kernel_cmd appropriately
* Improve Pry integration
* Add support for the gems gnuplot, gruff, rmagick and mini_magick
0.1.2 (2013-10-02)
* Support for Pry added
* Launch `iruby console` if plain `iruby` is started
0.1.0 (2013-10-02)
* Cleanup and rewrite of some parts
Carlos Agarie <carlos.agarie@gmail.com>
Damián Silvani <munshkr@gmail.com>
Dangyi Liu <LeedyPKU@gmail.com>
Daniel Mendler <mail@daniel-mendler.de>
Dimitris Zorbas <zorbash@skroutz.gr>
Domitry <domitry@gmail.com>
Jan Vlnas <git@jan.vlnas.cz>
John Woods <jwoods@vt.edu>
Josh Adams <josh@isotope11.com>
Julia Evans <julia@jvns.ca>
martin sarsale <martin@properati.com>
Matthias Bussonnier <bussonniermatthias@gmail.com>
Michael Hauser-Raspe <michael.hauser-raspe@cantab.net>
MinRK <benjaminrk@gmail.com>
Naoki Nishida <domitry@gmail.com>
Robby Clements <rclements@isotope11.com>
Spacewander <spacewanderlzx@gmail.com>
Takahiro Satoh <zalt50cc@gmail.com>
Robert Haines <robert.haines@manchester.ac.uk>
source 'https://rubygems.org'
gemspec
group :pry do
gem 'pry'
gem 'pry-doc'
gem 'awesome_print'
end
group :plot do
gem 'gnuplot'
gem 'rubyvis'
gem 'nyaplot', github: 'sciruby/nyaplot'
end
Copyright (c) 2013-2015 IRuby contributors and the Ruby Science Foundation
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***The current master branch and gem version >= 0.2 are compatible with IPython3/Jupyter. If you require IPython2 support, please install an older gem version < 0.2 or use the branch ipython2***
# IRuby
This is a Ruby kernel for IPython/Jupyter and is part of [SciRuby](http://sciruby.com/). You can try it at [try.jupyter.org](http://try.jupyter.org/).
![Screenshot](https://cloud.githubusercontent.com/assets/50754/7956845/3fa46df8-09e3-11e5-8641-f5b8669061b5.png)
### Quick start
The installation instructions are divided according to environments mainly because of ZeroMQ.
#### Ubuntu/Debian
At first install IPython/Jupyter. I recommend an installation using virtualenv.
sudo apt-get install python3-dev python-virtualenv
virtualenv -p python3 venv
source venv/bin/activate
pip install 'ipython[notebook]'
After that, install the Ruby gem.
gem install cztop
gem install iruby
Now you can run iruby with:
iruby notebook
#### Windows
At first install IPython/Jupyter. I recommend an installation using [Enthought Canopy](https://www.enthought.com/).
Run two commands below:
gem install cztop
gem install iruby
Now you can run iruby with:
iruby notebook
#### Mac
I recommend an installation using [Anaconda](https://store.continuum.io/cshop/anaconda/).
After that, run three commands shown below.
brew install libtool autoconf automake autogen
gem install cztop
gem install iruby
#### FreeBSD
At first install IPython/Jupyter.
There is a pyzmq ports (ports/net/py-pyzmq) which depends on libzmq4, however, it doesn't works with ipython.
Therefore we use libzmq3 like the following:
1. make your ports tree up-to-date.
2. replace LIBDEPENDS line in ports/net/py-pyzmq/Makefile
```shell
LIB_DEPENDS= libzmq.so:${PORTSDIR}/net/libzmq4
```
with
```shell
LIB_DEPENDS= libzmq.so:${PORTSDIR}/net/libzmq3
```
3. install related packages
```shell
$ sudo pkg install libzmq3 py27-qt4-gui py27-pexpect-3.3 py27-qt4-svg py27-pygments py27-Jinja2 py27-tornado py27-jsonschema
```
4. make install using ports
```shell
$ cd /usr/ports/net/py-pyzmq
$ sudo make install
$ cd /usr/ports/devel/ipython
$ sudo make install
```
Then, install iruby and related ports and gems.
```shell
$ sudo pkg install rubygem-mimemagic
$ sudo gem install ffi-rzmq # install ffi, ffi-rzmq-core and ffi-rzmq
$ git clone https://github.com/SciRuby/iruby.git
$ cd iruby
$ gem build iruby.gemspec
$ sudo gem install iruby-0.2.7.gem
```
### Installation for jRuby
Since jRuby is fully compatible with Ruby version 2.2, it is possible to use iruby with jRuby.
It can be helpful if you want to use java classes in your iruby notebook.
This will require the following software:
* jRuby version >= 9.0.4.0
* cztop gem
* this iruby gem
After installation, make sure that your `env` is set up to jruby.
```shell
$ env ruby -v
```
If you use RVM, it is enough to switch the current version to jruby.
If you have already used iruby with a different version, you need to generate a new kernel:
```shell
$ iruby register --force
```
After that you can use iruby with jRuby in usual way.
### After the installation
Take a look at the [example notebook](http://nbviewer.ipython.org/urls/raw.github.com/SciRuby/sciruby-notebooks/master/getting_started.ipynb)
and the [collection of notebooks](https://github.com/SciRuby/sciruby-notebooks/) which includes a Dockerfile to create a containerized installation of iruby
and other scientific gems. You can find the prebuild image at [dockerhub](https://registry.hub.docker.com/u/minad/sciruby-notebooks/).
### Required dependencies
* IPython/Jupyter >= 3.0.0
* Ruby >= 2.1.0
If you install IRuby with CZTop, CZMQ >= 4.0.0 is added to the list above.
If you install IRuby with ffi-rzmq, libzmq >= 3.2 is added to the list above.
### Authors
See the [CONTRIBUTORS](CONTRIBUTORS) file.
### License
Copyright © 2013-15, IRuby contributors and the Ruby Science Foundation.
All rights reserved.
IRuby, along with [SciRuby](http://sciruby.com/), is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.
require 'rake/testtask'
begin
require 'bundler/gem_tasks'
rescue Exception
end
Rake::TestTask.new('test') do |t|
t.libs << 'lib'
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
task default: 'test'
#!/usr/bin/env ruby
$:.unshift File.expand_path(__dir__ + '/../lib')
require 'iruby/command'
IRuby::Command.new(ARGV).run
# coding: utf-8
require_relative 'lib/iruby/version'
require 'date'
Gem::Specification.new do |s|
s.name = 'iruby'
s.date = Date.today.to_s
s.version = IRuby::VERSION
s.authors = ['Daniel Mendler', 'The SciRuby developers']
s.email = ['mail@daniel-mendler.de']
s.summary = 'Ruby Kernel for Jupyter/IPython'
s.description = 'A Ruby kernel for Jupyter/IPython frontends (e.g. notebook). Try it at try.jupyter.org.'
s.homepage = 'https://github.com/SciRuby/iruby'
s.license = 'MIT'
s.files = `git ls-files`.split($/)
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
s.test_files = s.files.grep(%r{^test/})
s.require_paths = %w(lib)
m = "Consider installing the optional dependencies to get additional functionality:\n"
File.read('Gemfile').scan(/gem\s+'(.*?)'/) { m << " * #{$1}\n" }
s.post_install_message = m << "\n"
s.required_ruby_version = '>= 2.1.0'
s.add_development_dependency 'rake', '~> 10.4'
s.add_development_dependency 'minitest', '~> 5.6'
s.add_runtime_dependency 'bond', '~> 0.5'
s.add_runtime_dependency 'multi_json', '~> 1.11'
s.add_runtime_dependency 'mimemagic', '~> 0.3'
s.add_runtime_dependency 'data_uri', '~> 0.1'
end
require 'mimemagic'
require 'multi_json'
require 'securerandom'
require 'openssl'
require 'tempfile'
require 'set'
require 'iruby/version'
require 'iruby/kernel'
require 'iruby/backend'
require 'iruby/ostream'
require 'iruby/input'
require 'iruby/formatter'
require 'iruby/utils'
require 'iruby/display'
require 'iruby/comm'
require 'iruby/session/mixin'
begin
require 'iruby/session/cztop'
rescue LoadError
begin
require 'iruby/session/rbczmq'
rescue LoadError
begin
require 'iruby/session/ffi_rzmq'
rescue LoadError
STDERR.puts "You should install cztop, rbczmq or ffi_rzmq before running iruby notebook. See README."
end
end
end
/* Placeholder for Ruby kernel.css */
// Ruby kernel.js
define(['base/js/namespace'], function(IPython) {
"use strict";
var onload = function() {
IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
var cells = IPython.notebook.get_cells();
for (var i in cells){
var c = cells[i];
if (c.cell_type === 'code')
c.code_mirror.setOption('indentUnit', 2);
}
}
return {onload:onload};
});
module IRuby
In, Out = [nil], [nil]
::In, ::Out = In, Out
module History
def eval(code, store_history)
b = TOPLEVEL_BINDING
b.local_variable_set(:_ih, In) unless b.local_variable_defined?(:_ih)
b.local_variable_set(:_oh, Out) unless b.local_variable_defined?(:_oh)
out = super
# TODO Add IRuby.cache_size which controls the size of the Out array
# and sets the oldest entries and _<n> variables to nil.
if store_history
b.local_variable_set("_#{Out.size}", out)
b.local_variable_set("_i#{In.size}", code)
Out << out
In << code
b.local_variable_set(:___, Out[-3])
b.local_variable_set(:__, Out[-2])
b.local_variable_set(:_, Out[-1])
b.local_variable_set(:_iii, In[-3])
b.local_variable_set(:_ii, In[-2])
b.local_variable_set(:_i, In[-1])
end
out
end
end
class PlainBackend
prepend History
def initialize
require 'bond'
Bond.start(debug: true)
end
def eval(code, store_history)
TOPLEVEL_BINDING.eval(code)
end
def complete(code)
Bond.agent.call(code, code)
end
end
class PryBackend
prepend History
def initialize
require 'pry'
Pry.memory_size = 3
Pry.pager = false # Don't use the pager
Pry.print = proc {|output, value|} # No result printing
Pry.exception_handler = proc {|output, exception, _| }
reset
end
def eval(code, store_history)
@pry.last_result = nil
unless @pry.eval(code)
reset
raise SystemExit
end
unless @pry.eval_string.empty?
syntax_error = @pry.eval_string
@pry.reset_eval_string
@pry.evaluate_ruby syntax_error
end
raise @pry.last_exception if @pry.last_result_is_exception?
@pry.push_initial_binding unless @pry.current_binding # ensure that we have a binding
@pry.last_result
end
def complete(code)
@pry.complete(code)
end
def reset
@pry = Pry.new(output: $stdout, target: TOPLEVEL_BINDING)
end
end
end
module IRuby
# Comm is a new messaging system for bidirectional communication.
# Both kernel and front-end listens for messages.
class Comm
attr_writer :on_msg, :on_close
class << self
def target; @target ||= {} end
def comm; @comm ||= {} end
end
def initialize(target_name, comm_id = SecureRandom.uuid)
@target_name, @comm_id = target_name, comm_id
end
def open(**data)
Kernel.instance.session.send(:publish, :comm_open, comm_id: @comm_id, data: data, target_name: @target_name)
Comm.comm[@comm_id] = self
end
def send(**data)
Kernel.instance.session.send(:publish, :comm_msg, comm_id: @comm_id, data: data)
end
def close(**data)
Kernel.instance.session.send(:publish, :comm_close, comm_id: @comm_id, data: data)
Comm.comm.delete(@comm_id)
end
def on_msg(&b)
@on_msg = b
end
def on_close(&b)
@on_close = b
end
def handle_msg(data)
@on_msg.call(data) if @on_msg
end
def handle_close(data)
@on_close.call(data) if @on_close
end
end
end
require 'fileutils'
require 'multi_json'
module IRuby
class Command
def initialize(args)
@args = args
ipython_dir = ENV['IPYTHONDIR'] || '~/.ipython'
@args.each do |arg|
ipython_dir = $1 if arg =~ /\A--ipython-dir=(.*)\Z/
end
@kernel_dir = File.join(File.expand_path(ipython_dir), 'kernels', 'ruby')
@kernel_file = File.join(@kernel_dir, 'kernel.json')
@iruby_path = File.expand_path $0
end
def run
case @args.first
when 'version', '-v', '--version'
require 'iruby/version'
puts "IRuby #{IRuby::VERSION}, Ruby #{RUBY_VERSION}"
when 'help', '-h', '--help'
print_help
when 'register'
if registered_iruby_path && !@args.include?('--force')
STDERR.puts "#{@kernel_file} already exists!\nUse --force to force a register."
exit 1
end
register_kernel
when 'unregister'
unregister_kernel
when 'kernel'
run_kernel
else
run_ipython
end
end
private
def print_help
puts %{
Usage:
iruby register Register IRuby kernel in #{@kernel_file}.
iruby unregister Unregister IRuby kernel.
iruby console Launch the IRuby terminal-based console.
iruby notebook Launch the IRuby HTML notebook server.
... Same as IPython.
Please note that IRuby accepts the same parameters as IPython.
Try `ipython help` for more information.
}
end
def run_kernel
require 'iruby/logger'
IRuby.logger = MultiLogger.new(*Logger.new(STDOUT))
@args.reject! {|arg| arg =~ /\A--log=(.*)\Z/ && IRuby.logger.loggers << Logger.new($1) }
IRuby.logger.level = @args.delete('--debug') ? Logger::DEBUG : Logger::INFO
raise(ArgumentError, 'Not enough arguments to the kernel') if @args.size < 2 || @args.size > 4
config_file, boot_file, working_dir = @args[1..-1]
Dir.chdir(working_dir) if working_dir
require boot_file if boot_file
check_bundler {|e| IRuby.logger.warn "Could not load bundler: #{e.message}\n#{e.backtrace.join("\n")}" }
require 'iruby'
Kernel.new(config_file).run
rescue Exception => e
IRuby.logger.fatal "Kernel died: #{e.message}\n#{e.backtrace.join("\n")}"
raise
end
def check_version
required = '3.0.0'
version = `ipython --version`.chomp
if version < required
STDERR.puts "Your IPython version #{version} is too old, at least #{required} is required"
exit 1
end
end
def run_ipython
# If no command is given, we use the console to launch the whole 0MQ-client-server stack
@args = %w(console) + @args if @args.first.to_s !~ /\A\w/
@args += %w(--kernel ruby) if %w(console qtconsole).include? @args.first
check_version
check_registered_kernel
check_bundler {|e| STDERR.puts "Could not load bundler: #{e.message}" }
Kernel.exec('ipython', *@args)
end
def check_registered_kernel
if kernel = registered_iruby_path
STDERR.puts "#{@iruby_path} differs from registered path #{registered_iruby_path}.
This might not work. Run 'iruby register --force' to fix it." if @iruby_path != kernel
else
register_kernel
end
end
def check_bundler
require 'bundler'
raise %q{iruby is missing from Gemfile. This might not work.
Add `gem 'iruby'` to your Gemfile to fix it.} unless Bundler.definition.specs.any? {|s| s.name == 'iruby' }
Bundler.setup
rescue LoadError
rescue Exception => e
yield(e)
end
def register_kernel
FileUtils.mkpath(@kernel_dir)
unless RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin/
File.write(@kernel_file, MultiJson.dump(argv: [ @iruby_path, 'kernel', '{connection_file}' ],
display_name: "Ruby #{RUBY_VERSION}", language: 'ruby'))
else
ruby_path, iruby_path = [RbConfig.ruby, @iruby_path].map{|path| path.gsub('/', '\\\\')}
File.write(@kernel_file, MultiJson.dump(argv: [ ruby_path, iruby_path, 'kernel', '{connection_file}' ],
display_name: "Ruby #{RUBY_VERSION}", language: 'ruby'))
end