jupyter_on_rails 0.5.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e9bb122b865f0be411380b179256dcaec81418fb45b208a973b75cc95138c62
4
- data.tar.gz: 060bb8671e299289e377c4119d3560265262356d859bb77de55e4c2714b201d6
3
+ metadata.gz: 2268bbfe0e3ad39f35573c40385e05fcf526b24dc942ffa1c99942bdf2efffb9
4
+ data.tar.gz: 127d4f8764f90c27ad74cb9ea8b2ea3ed9148ea156ecbc8189409aba9bf22de8
5
5
  SHA512:
6
- metadata.gz: bac938faecc1a941d74e3aaf2217784767af6c7245c6d4612a2c679c1455b9927246ea4db6c1cda6b23895badbc8533e1c9359870f919e8a69c218d6ed4a67af
7
- data.tar.gz: da7b122b1abc9b90aa7f4f0c58ee803498fb61d426eec47b804eec2aef6f140c577f3ad67bcd59adf1051b8dedd8ea8766349f55f50d7d18e1c1f6445bf66ec7
6
+ metadata.gz: 631d2aa1fd6a8131a8b508355f5520a3375670feac73e5f0abe14a3067617c54392cbdd9ab554153a5bc0d87fc5c3ba71c3fb52c4219752fce4d4374d6370666
7
+ data.tar.gz: 034fe771d3ca2f45db395ce3d259eb76186523423e7fc9a21f9f64f2c473b24ed28bab73b856d06961bb519412c004286144cad4bb31c712567ff2e084a7178d
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ Gemspec/RequiredRubyVersion:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 160
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/ClassAndModuleChildren:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Max: 100
15
+
16
+ Metrics/MethodLength:
17
+ Max: 60
18
+
19
+ Metrics/PerceivedComplexity:
20
+ Max: 20
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 20
24
+
25
+ Style/MultilineTernaryOperator:
26
+ Enabled: false
27
+
28
+ Lint/SuppressedException:
29
+ Enabled: false
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in jupyter_on_rails.gemspec
6
8
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,192 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jupyter_on_rails (0.9.0)
5
+ daru
6
+ iruby
7
+ railties
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (6.1.3.2)
13
+ actionview (= 6.1.3.2)
14
+ activesupport (= 6.1.3.2)
15
+ rack (~> 2.0, >= 2.0.9)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
+ actionview (6.1.3.2)
20
+ activesupport (= 6.1.3.2)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.4)
23
+ rails-dom-testing (~> 2.0)
24
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
25
+ activesupport (6.1.3.2)
26
+ concurrent-ruby (~> 1.0, >= 1.0.2)
27
+ i18n (>= 1.6, < 2)
28
+ minitest (>= 5.1)
29
+ tzinfo (~> 2.0)
30
+ zeitwerk (~> 2.3)
31
+ addressable (2.7.0)
32
+ public_suffix (>= 2.0.2, < 5.0)
33
+ ast (2.4.2)
34
+ async (1.29.0)
35
+ console (~> 1.10)
36
+ nio4r (~> 2.3)
37
+ timers (~> 4.1)
38
+ async-http (0.56.2)
39
+ async (~> 1.25)
40
+ async-io (~> 1.28)
41
+ async-pool (~> 0.2)
42
+ protocol-http (~> 0.22.0)
43
+ protocol-http1 (~> 0.14.0)
44
+ protocol-http2 (~> 0.14.0)
45
+ async-http-faraday (0.9.0)
46
+ async-http (~> 0.42)
47
+ faraday
48
+ async-io (1.31.0)
49
+ async (~> 1.14)
50
+ async-pool (0.3.6)
51
+ async (~> 1.25)
52
+ backports (3.21.0)
53
+ builder (3.2.4)
54
+ bump (0.10.0)
55
+ concurrent-ruby (1.1.8)
56
+ console (1.12.0)
57
+ fiber-local
58
+ crass (1.0.6)
59
+ daru (0.3)
60
+ packable (~> 1.3.13)
61
+ data_uri (0.1.0)
62
+ erubi (1.10.0)
63
+ faraday (1.4.2)
64
+ faraday-em_http (~> 1.0)
65
+ faraday-em_synchrony (~> 1.0)
66
+ faraday-excon (~> 1.1)
67
+ faraday-net_http (~> 1.0)
68
+ faraday-net_http_persistent (~> 1.1)
69
+ multipart-post (>= 1.2, < 3)
70
+ ruby2_keywords (>= 0.0.4)
71
+ faraday-em_http (1.0.0)
72
+ faraday-em_synchrony (1.0.0)
73
+ faraday-excon (1.1.0)
74
+ faraday-http-cache (2.2.0)
75
+ faraday (>= 0.8)
76
+ faraday-net_http (1.0.1)
77
+ faraday-net_http_persistent (1.1.0)
78
+ ffi (1.15.1)
79
+ ffi-rzmq (2.0.7)
80
+ ffi-rzmq-core (>= 1.0.7)
81
+ ffi-rzmq-core (1.0.7)
82
+ ffi
83
+ fiber-local (1.0.0)
84
+ github_changelog_generator (1.16.3)
85
+ activesupport
86
+ async (>= 1.25.0)
87
+ async-http-faraday
88
+ faraday-http-cache
89
+ multi_json
90
+ octokit (~> 4.6)
91
+ rainbow (>= 2.2.1)
92
+ rake (>= 10.0)
93
+ retriable (~> 3.0)
94
+ i18n (1.8.10)
95
+ concurrent-ruby (~> 1.0)
96
+ io-console (0.5.9)
97
+ irb (1.3.5)
98
+ reline (>= 0.1.5)
99
+ iruby (0.7.0)
100
+ data_uri (~> 0.1)
101
+ ffi-rzmq
102
+ irb
103
+ mime-types (>= 3.3.1)
104
+ multi_json (~> 1.11)
105
+ loofah (2.9.1)
106
+ crass (~> 1.0.2)
107
+ nokogiri (>= 1.5.9)
108
+ method_source (1.0.0)
109
+ mime-types (3.3.1)
110
+ mime-types-data (~> 3.2015)
111
+ mime-types-data (3.2021.0225)
112
+ mini_portile2 (2.5.1)
113
+ minitest (5.14.4)
114
+ multi_json (1.15.0)
115
+ multipart-post (2.1.1)
116
+ nio4r (2.5.7)
117
+ nokogiri (1.11.6)
118
+ mini_portile2 (~> 2.5.0)
119
+ racc (~> 1.4)
120
+ octokit (4.21.0)
121
+ faraday (>= 0.9)
122
+ sawyer (~> 0.8.0, >= 0.5.3)
123
+ packable (1.3.14)
124
+ backports
125
+ parallel (1.20.1)
126
+ parser (3.0.1.1)
127
+ ast (~> 2.4.1)
128
+ protocol-hpack (1.4.2)
129
+ protocol-http (0.22.0)
130
+ protocol-http1 (0.14.1)
131
+ protocol-http (~> 0.22)
132
+ protocol-http2 (0.14.2)
133
+ protocol-hpack (~> 1.4)
134
+ protocol-http (~> 0.18)
135
+ public_suffix (4.0.6)
136
+ racc (1.5.2)
137
+ rack (2.2.3)
138
+ rack-test (1.1.0)
139
+ rack (>= 1.0, < 3)
140
+ rails-dom-testing (2.0.3)
141
+ activesupport (>= 4.2.0)
142
+ nokogiri (>= 1.6)
143
+ rails-html-sanitizer (1.3.0)
144
+ loofah (~> 2.3)
145
+ railties (6.1.3.2)
146
+ actionpack (= 6.1.3.2)
147
+ activesupport (= 6.1.3.2)
148
+ method_source
149
+ rake (>= 0.8.7)
150
+ thor (~> 1.0)
151
+ rainbow (3.0.0)
152
+ rake (13.0.3)
153
+ regexp_parser (2.1.1)
154
+ reline (0.2.5)
155
+ io-console (~> 0.5)
156
+ retriable (3.1.2)
157
+ rexml (3.2.5)
158
+ rubocop (1.15.0)
159
+ parallel (~> 1.10)
160
+ parser (>= 3.0.0.0)
161
+ rainbow (>= 2.2.2, < 4.0)
162
+ regexp_parser (>= 1.8, < 3.0)
163
+ rexml
164
+ rubocop-ast (>= 1.5.0, < 2.0)
165
+ ruby-progressbar (~> 1.7)
166
+ unicode-display_width (>= 1.4.0, < 3.0)
167
+ rubocop-ast (1.6.0)
168
+ parser (>= 3.0.1.1)
169
+ ruby-progressbar (1.11.0)
170
+ ruby2_keywords (0.0.4)
171
+ sawyer (0.8.2)
172
+ addressable (>= 2.3.5)
173
+ faraday (> 0.8, < 2.0)
174
+ thor (1.1.0)
175
+ timers (4.3.3)
176
+ tzinfo (2.0.4)
177
+ concurrent-ruby (~> 1.0)
178
+ unicode-display_width (2.0.0)
179
+ zeitwerk (2.4.2)
180
+
181
+ PLATFORMS
182
+ ruby
183
+
184
+ DEPENDENCIES
185
+ bump
186
+ github_changelog_generator
187
+ jupyter_on_rails!
188
+ rake
189
+ rubocop
190
+
191
+ BUNDLED WITH
192
+ 2.2.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Yuki Inoue
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -14,7 +14,10 @@ managing the jupyter configuration installed in user global area (the iruby kern
14
14
 
15
15
  With this gem, these awkwardness is to solved by following instruments:
16
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.
17
+ * This rake task automatically creates two `iruby` kernels to load your application in Jupyter:
18
+ * one for normal operation
19
+ * one for sandbox mode in which everything you do is wrapped in a database transaction that is rolled back when the
20
+ kernel exits (equivalent to `rails console --sandbox`)
18
21
 
19
22
 
20
23
  ## Prerequisites
@@ -58,10 +61,11 @@ rake jupyter:notebook
58
61
  Eventually, you'll have jupyter opened, and the kernel being available.
59
62
 
60
63
 
61
- ### ApplicationRecord#to_df
64
+ ### ApplicationRecord.to_df/#to_df
62
65
 
63
66
  ```ruby
64
67
  User.to_df # => Daru::DataFrame is returned
68
+ user.to_df # => Daru::DataFrame for single record
65
69
  ```
66
70
 
67
71
  ### Daru::DataFrame#write_model
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "jupyter_on_rails"
4
+ require 'bundler/setup'
5
+ require 'jupyter_on_rails'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "jupyter_on_rails"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,45 +1,47 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "jupyter_on_rails/version"
5
+ require 'jupyter_on_rails/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "jupyter_on_rails"
8
+ spec.name = 'jupyter_on_rails'
8
9
  spec.version = JupyterOnRails::VERSION
9
- spec.authors = ["Yuki INOUE"]
10
- spec.email = ["inoueyuworks@gmail.com"]
10
+ spec.authors = ['Yuki INOUE']
11
+ spec.email = ['inoueyuworks@gmail.com']
11
12
 
12
- spec.summary = %q{Integrate jupyter into rails}
13
- spec.description = %q{Utilities for integrating jupyter and rails.}
14
- spec.homepage = "https://github.com/Yuki-Inoue/jupyter_on_rails"
13
+ spec.summary = 'Integrate jupyter into rails'
14
+ spec.description = 'Utilities for integrating jupyter and rails.'
15
+ spec.homepage = 'https://github.com/Yuki-Inoue/jupyter_on_rails'
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
19
  if spec.respond_to?(:metadata)
19
- spec.metadata["allowed_push_host"] = 'https://rubygems.org'
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
21
 
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = "https://github.com/Yuki-Inoue/jupyter_on_rails"
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = 'https://github.com/Yuki-Inoue/jupyter_on_rails'
23
24
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
25
  else
25
- raise "RubyGems 2.0 or newer is required to protect against " \
26
- "public gem pushes."
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
27
28
  end
28
29
 
29
30
  # Specify which files should be added to the gem when it is released.
30
31
  # 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
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
33
  `git ls-files -z`.split("\x0")
33
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
34
- .reject { |f| f.match(/\.png$/) }
34
+ .reject { |f| f.match(%r{^(test|spec|features|\.github)/}) }
35
+ .reject { |f| f.match(/(\.gitignore|\.png)$/) }
35
36
  end
36
- spec.bindir = "exe"
37
+ spec.bindir = 'exe'
37
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
- spec.require_paths = ["lib"]
39
+ spec.require_paths = ['lib']
39
40
 
40
- spec.add_development_dependency "rake"
41
- spec.add_development_dependency 'github_changelog_generator'
42
41
  spec.add_development_dependency 'bump'
42
+ spec.add_development_dependency 'github_changelog_generator'
43
+ spec.add_development_dependency 'rake'
44
+ spec.add_development_dependency 'rubocop'
43
45
 
44
46
  spec.add_dependency 'iruby'
45
47
  spec.add_dependency 'railties'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jupyter_on_rails/version'
2
4
 
3
5
  module JupyterOnRails
@@ -1,14 +1,5 @@
1
- root = ENV.fetch('RAILS_ROOT')
1
+ # frozen_string_literal: true
2
2
 
3
- boot_file = File.expand_path('config/boot.rb', root)
4
- require boot_file
3
+ require 'jupyter_on_rails/kernel'
5
4
 
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
5
+ JupyterOnRails::Kernel.new.boot
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jupyter_on_rails/kernel'
4
+
5
+ JupyterOnRails::Kernel.new(sandbox: true).boot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module JupyterOnRails
@@ -5,6 +7,7 @@ module JupyterOnRails
5
7
  module ActiveRecordExt
6
8
  extend ::ActiveSupport::Concern
7
9
 
10
+ # Rails 4.0 support
8
11
  unless respond_to?(:class_methods)
9
12
  def self.class_methods(&class_methods_module_definition)
10
13
  mod = const_defined?(:ClassMethods, false) ?
@@ -44,6 +47,10 @@ module JupyterOnRails
44
47
  ::Daru::DataFrame.new(datas)
45
48
  end
46
49
  end
50
+
51
+ def to_df
52
+ ::Daru::DataFrame.new([attributes])
53
+ end
47
54
  end
48
55
  end
49
56
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JupyterOnRails
2
4
  module Daru
3
5
  module DataFrameExt
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JupyterOnRails
4
+ module Initializer
5
+ def self.run(root:, sandbox:)
6
+ # Load Daru extensions
7
+ begin
8
+ require 'daru'
9
+ require 'active_record'
10
+ rescue LoadError
11
+ else
12
+ require 'jupyter_on_rails/daru/active_record_ext'
13
+ require 'jupyter_on_rails/daru/data_frame_ext'
14
+
15
+ ::ActiveRecord::Base.instance_eval do
16
+ include ::JupyterOnRails::Daru::ActiveRecordExt
17
+ end
18
+ ::Daru::DataFrame.instance_eval do
19
+ include ::JupyterOnRails::Daru::DataFrameExt
20
+ end
21
+ end
22
+
23
+ original = Dir.pwd
24
+ Dir.chdir root
25
+ app_file = File.expand_path('config/environment.rb', root)
26
+ require app_file
27
+ Rails.application.require_environment!
28
+ Dir.chdir original
29
+
30
+ return unless sandbox
31
+
32
+ ActiveRecord::Base.connection.begin_transaction(joinable: false)
33
+ at_exit do
34
+ ActiveRecord::Base.connection.rollback_transaction
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JupyterOnRails
4
+ class Kernel
5
+ def initialize(sandbox: false)
6
+ @root = ENV.fetch('RAILS_ROOT')
7
+ @sandbox = sandbox
8
+ end
9
+
10
+ def boot
11
+ boot_rails
12
+ load_extensions
13
+ end
14
+
15
+ private
16
+
17
+ def boot_rails
18
+ boot_file = File.expand_path('config/boot.rb', @root)
19
+ require boot_file
20
+ end
21
+
22
+ def load_extensions
23
+ require_relative 'initializer'
24
+
25
+ require 'iruby'
26
+ IRuby::Kernel.events.register(:initialized) do |_kernel|
27
+ JupyterOnRails::Initializer.run(root: @root, sandbox: @sandbox)
28
+ end
29
+
30
+ IRuby::Display::Registry.instance_eval do
31
+ match do |obj|
32
+ obj.is_a?(ActiveRecord::Relation) ||
33
+ obj.is_a?(::Class) && obj < ActiveRecord::Base && !obj.abstract_class
34
+ end
35
+ priority 100
36
+ format 'text/html' do |obj|
37
+ n = 10
38
+ puts "finding top #{n}"
39
+ obj.limit(n).to_df.to_html
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'daru/active_record_ext'
2
4
  require_relative 'daru/data_frame_ext'
3
5
 
@@ -6,21 +8,5 @@ module JupyterOnRails
6
8
  rake_tasks do
7
9
  load 'jupyter_on_rails/railtie/jupyter.rake'
8
10
  end
9
-
10
- config.before_configuration do
11
- begin
12
- require 'daru'
13
- rescue LoadError
14
- end
15
-
16
- if defined?(::Daru) && defined?(::ActiveRecord)
17
- class ::ActiveRecord::Base
18
- include ::JupyterOnRails::Daru::ActiveRecordExt
19
- end
20
- class ::Daru::DataFrame
21
- include ::JupyterOnRails::Daru::DataFrameExt
22
- end
23
- end
24
- end
25
11
  end
26
12
  end
@@ -1,30 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'shellwords'
2
4
  require 'json'
5
+ require 'ostruct'
3
6
 
7
+ # rubocop:disable Metrics/BlockLength
4
8
  namespace :jupyter do
5
9
  desc 'start jupyter notebook'
6
- task :notebook do
10
+ task notebook: :install_kernels do
11
+ ipython_dir = ENV['IPYTHONDIR'] || Rails.root / '.ipython'
12
+
13
+ env = { 'JUPYTER_DATA_DIR' => ipython_dir.to_s }
14
+ commands = %w[jupyter notebook]
15
+ commands = %w[pipenv run] + commands if (Rails.root / 'Pipfile').exist?
16
+ Process.exec(env, *commands)
17
+ end
18
+
19
+ desc 'Install the kernel'
20
+ task :install_kernels do
7
21
  root = Rails.root
8
22
  ipython_dir = ENV['JUPYTER_DATA_DIR'] || ENV['IPYTHONDIR'] || root / '.ipython'
9
23
  ipython_dir = File.absolute_path(ipython_dir.to_s)
24
+ application_module =
25
+ if Rails::VERSION::MAJOR >= 6
26
+ Rails.application.class.module_parent
27
+ else
28
+ Rails.application.class.parent
29
+ end
10
30
 
11
31
  sh "JUPYTER_DATA_DIR=#{Shellwords.shellescape(ipython_dir.to_s)} bundle exec iruby register --force"
12
32
 
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"
33
+ [
34
+ OpenStruct.new(kernel_name: 'rails', boot_file: '../boot.rb', name_ext: ''),
35
+ OpenStruct.new(kernel_name: 'rails-sandbox', boot_file: '../boot_sandbox.rb', name_ext: ', sandbox')
36
+ ].each do |cfg|
37
+ sh "rm -rf #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/#{cfg.kernel_name}"
15
38
 
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
39
+ sh "cp -r #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/ruby #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/#{cfg.kernel_name}"
22
40
 
23
- File.write(kernel_file, JSON.dump(kernel_h))
41
+ kernel_file = File.expand_path("kernels/#{cfg.kernel_name}/kernel.json", ipython_dir.to_s)
42
+ kernel_h = JSON.parse(File.read(kernel_file))
43
+ kernel_h['argv'] << File.expand_path(cfg.boot_file, __dir__)
44
+ kernel_h['display_name'] = "#{application_module} (rails #{Rails.version}#{cfg.name_ext})"
45
+ kernel_h['env'] ||= {}
46
+ kernel_h['env']['RAILS_ROOT'] = root.to_s
24
47
 
25
- env = { 'JUPYTER_DATA_DIR' => ipython_dir.to_s }
26
- commands = %w[jupyter notebook]
27
- commands = %w[pipenv run] + commands if (root / 'Pipfile').exist?
28
- Process.exec(env, *commands)
48
+ File.write(kernel_file, JSON.dump(kernel_h))
49
+ end
29
50
  end
30
51
  end
52
+ # rubocop:enable Metrics/BlockLength
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JupyterOnRails
2
- VERSION = '0.5.6'
4
+ VERSION = '0.9.0'
3
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jupyter_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki INOUE
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-15 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: bump
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -39,7 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bump
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -101,10 +115,11 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - ".github/FUNDING.yml"
105
- - ".gitignore"
118
+ - ".rubocop.yml"
106
119
  - CHANGELOG.md
107
120
  - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE
108
123
  - README.md
109
124
  - Rakefile
110
125
  - bin/console
@@ -112,9 +127,11 @@ files:
112
127
  - jupyter_on_rails.gemspec
113
128
  - lib/jupyter_on_rails.rb
114
129
  - lib/jupyter_on_rails/boot.rb
130
+ - lib/jupyter_on_rails/boot_sandbox.rb
115
131
  - lib/jupyter_on_rails/daru/active_record_ext.rb
116
132
  - lib/jupyter_on_rails/daru/data_frame_ext.rb
117
- - lib/jupyter_on_rails/iruby_kernel_extention.rb
133
+ - lib/jupyter_on_rails/initializer.rb
134
+ - lib/jupyter_on_rails/kernel.rb
118
135
  - lib/jupyter_on_rails/railtie.rb
119
136
  - lib/jupyter_on_rails/railtie/jupyter.rake
120
137
  - lib/jupyter_on_rails/version.rb
@@ -124,7 +141,7 @@ metadata:
124
141
  allowed_push_host: https://rubygems.org
125
142
  homepage_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
126
143
  source_code_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
127
- post_install_message:
144
+ post_install_message:
128
145
  rdoc_options: []
129
146
  require_paths:
130
147
  - lib
@@ -139,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
156
  - !ruby/object:Gem::Version
140
157
  version: '0'
141
158
  requirements: []
142
- rubygems_version: 3.1.2
143
- signing_key:
159
+ rubygems_version: 3.2.3
160
+ signing_key:
144
161
  specification_version: 4
145
162
  summary: Integrate jupyter into rails
146
163
  test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,2 +0,0 @@
1
-
2
- issuehunt: yuki-inoue
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
- /vendor
@@ -1,18 +0,0 @@
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/environment.rb', root)
12
- require app_file
13
- Rails.application.require_environment!
14
- Dir.chdir original
15
- super
16
- end
17
- end
18
- end