jupyter_on_rails 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23abc55bf5cdbb25fcedc441594b67deba55617f1064376785719b254e1dd1fe
4
+ data.tar.gz: b1f90644a6c73ebb3bb798064012f4db785683542df034c15ea37aabd4d8fdeb
5
+ SHA512:
6
+ metadata.gz: 82d708ee1ed8ec629a3eb2fa4cec1b7b356ef6849bf4d3c5574e8b5a7e6ef1fca5a7071f0d51e8d3576535c1bfdc5fa7cd310aede308f0e9e88cce4cd46e5d66
7
+ data.tar.gz: 618abf46f0a4977e5ff9129b22bbfef5924254fd3240030802e323cb51f265e85c4593f9037d61a6eac28a63a5767ef7d6f31a5645de5659aa236108c5bf53d2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jupyter_on_rails.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # JupyterOnRails
2
+
3
+ Rails is loaded on jupyter dead easy.
4
+
5
+ ![Alt text](the_screenshot.png?raw=true "Title")
6
+
7
+ ## Motivation
8
+
9
+ Although it was already possible to run `jupyter` + `iruby` and `require app_full_path` to load Rails application context,
10
+ it is a bit tiring to each time copy all the `require` statements.
11
+
12
+ Moreover, since Rails Way works in keeping (generally) everything under the project directory,
13
+ managing the jupyter configuration installed in user global area (the iruby kernel register thing) is again a bit awkward.
14
+
15
+ With this gem, these awkwardness is to solved by following instruments:
16
+ * `rake jupyter:notebook` Railtie command which invokes jupyter at your project root, and
17
+ * The rails kernel dynamically defined by the rake task which automatically loads your Rails application.
18
+
19
+
20
+ ## Prerequisites
21
+
22
+ * iruby's prerequisites must be met.
23
+ * Refer: https://github.com/SciRuby/iruby
24
+ * Either `cztop` or `ffi-rzmq` gem must be installable.
25
+
26
+ * `jupyter` command must be somehow available.
27
+ * Either
28
+ * `jupyter` command (pip global install, anaconda, etc), or
29
+ * `pipenv run jupyter` command (managed by Pipfile at project root)
30
+
31
+ ## Installation
32
+
33
+ Add these lines to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'jupyter_on_rails'
37
+
38
+ # For sessions pick either:
39
+ gem 'ffi-rzmq'
40
+ # Or
41
+ gem 'cztop'
42
+ ```
43
+
44
+ And then execute:
45
+
46
+ $ bundle install
47
+
48
+ ## Usage
49
+
50
+ Starting the jupyter server is available as a rake command.
51
+
52
+ Just execute:
53
+
54
+ ```sh
55
+ rake jupyter:notebook
56
+ ```
57
+
58
+ Eventually, you'll have jupyter opened, and the kernel being available.
59
+
60
+ ## Development
61
+
62
+ This is a railtie gem, so you'd probably want to do something like:
63
+
64
+ ```
65
+ gem 'jupyter_on_rails', git: 'GIT_URL_OF_YOUR_REPO',
66
+ branch: 'the-work-branch'
67
+ ```
68
+
69
+ or
70
+
71
+ ```
72
+ gem `jupyter_on_rails`, path: 'jupyter_on_rails_as_sub_project'
73
+ ```
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Yuki-Inoue/jupyter_on_rails.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jupyter_on_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jupyter_on_rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jupyter_on_rails"
8
+ spec.version = JupyterOnRails::VERSION
9
+ spec.authors = ["Yuki INOUE"]
10
+ spec.email = ["inoueyuworks@gmail.com"]
11
+
12
+ spec.summary = %q{Integrate jupyter into rails}
13
+ spec.description = %q{`rails jupyter:notebook` to open jupyter with rails app kernel of your project.}
14
+ spec.homepage = "https://github.com/Yuki-Inoue/jupyter_on_rails"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/Yuki-Inoue/jupyter_on_rails"
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+
41
+ spec.add_dependency 'railties'
42
+ spec.add_dependency 'iruby'
43
+ end
@@ -0,0 +1,14 @@
1
+ root = ENV.fetch('RAILS_ROOT')
2
+
3
+ boot_file = File.expand_path('config/boot.rb', root)
4
+ require boot_file
5
+
6
+ require_relative 'iruby_kernel_extention'
7
+ JupyterOnRails::IRubyKernelExtention.root = root
8
+
9
+ require 'iruby'
10
+ module IRuby
11
+ class Kernel
12
+ prepend JupyterOnRails::IRubyKernelExtention
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module JupyterOnRails
2
+ module IRubyKernelExtention
3
+ class << self
4
+ attr_accessor :root
5
+ end
6
+
7
+ def run
8
+ original = Dir.pwd
9
+ root = IRubyKernelExtention.root
10
+ Dir.chdir root
11
+ app_file = File.expand_path('config/application.rb', root)
12
+ require app_file
13
+ Rails.application.require_environment!
14
+ Dir.chdir original
15
+ super
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'shellwords'
2
+ require 'json'
3
+
4
+ namespace :jupyter do
5
+ desc 'start jupyter notebook'
6
+ task :notebook do
7
+ root = Rails.root
8
+ ipython_dir = ENV['IPYTHONDIR'] || root / '.ipython'
9
+ ipython_dir = File.absolute_path(ipython_dir.to_s)
10
+
11
+ sh "bundle exec iruby register --force --ipython-dir=#{Shellwords.shellescape(ipython_dir.to_s)}"
12
+
13
+ sh "rm -rf #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/rails"
14
+ sh "cp -r #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/ruby #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/rails"
15
+
16
+ kernel_file = File.expand_path('kernels/rails/kernel.json', ipython_dir.to_s)
17
+ kernel_h = JSON.parse(File.read(kernel_file))
18
+ kernel_h['argv'] << File.expand_path('../boot.rb', __dir__)
19
+ kernel_h['display_name'] = "#{Rails.application.class.parent} (rails #{Rails.version})"
20
+ kernel_h['env'] ||= {}
21
+ kernel_h['env']['RAILS_ROOT'] = root.to_s
22
+
23
+ File.write(kernel_file, JSON.dump(kernel_h))
24
+
25
+ env = { 'IPYTHONDIR' => ipython_dir.to_s }
26
+ commands = %w[jupyter notebook]
27
+ commands = %w[pipenv run] + commands if (root / 'Pipfile').exist?
28
+ Process.exec(env, *commands)
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ module JupyterOnRails
2
+ class Railtie < ::Rails::Railtie
3
+ rake_tasks do
4
+ load 'jupyter_on_rails/railtie/jupyter.rake'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module JupyterOnRails
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'jupyter_on_rails/version'
2
+
3
+ module JupyterOnRails
4
+ class Error < StandardError; end
5
+ end
6
+
7
+ require 'jupyter_on_rails/railtie' if defined?(Rails)
Binary file
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jupyter_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuki INOUE
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: iruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "`rails jupyter:notebook` to open jupyter with rails app kernel of your
70
+ project."
71
+ email:
72
+ - inoueyuworks@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - jupyter_on_rails.gemspec
84
+ - lib/jupyter_on_rails.rb
85
+ - lib/jupyter_on_rails/boot.rb
86
+ - lib/jupyter_on_rails/iruby_kernel_extention.rb
87
+ - lib/jupyter_on_rails/railtie.rb
88
+ - lib/jupyter_on_rails/railtie/jupyter.rake
89
+ - lib/jupyter_on_rails/version.rb
90
+ - the_screenshot.png
91
+ homepage: https://github.com/Yuki-Inoue/jupyter_on_rails
92
+ licenses: []
93
+ metadata:
94
+ allowed_push_host: https://rubygems.org
95
+ homepage_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
96
+ source_code_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Integrate jupyter into rails
116
+ test_files: []