jupyter_on_rails 0.5.3 → 0.7.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: 21a8ae6b4a482e324dbb5cee23c4239bf9ec489b3fe6a6bf31e2f7ebccc8f612
4
- data.tar.gz: e72c9b01472338ac1e948201d1dcce66f30fe57921660becb126219d83c7ba54
3
+ metadata.gz: d4dd954da8ae0ebe5bad32d7b98acb1dbde79b0f3b6bcd837d019f11085b50f8
4
+ data.tar.gz: 992c4ab71f53ba0b59752558e7cbaf932de72e9d6db4ac38a4ab5bef595b655c
5
5
  SHA512:
6
- metadata.gz: cfb93042494c2f9f4a831d95059afaa1ab49dac9be49d93055debe7c70c1a9ecad0d0877fe61c98a183e1af1f5ff96abb703fba5765ee8963d745c71c770e584
7
- data.tar.gz: '040793452a6e5b6c40b2c69bc5335cde56e8a51ae90d996e20dd817807857406e78f8aa38272049d422f732af6c0d81db83b85ac4f1f8cbb10f6b624b70e548c'
6
+ metadata.gz: 48132a0169aad90d07c55297efe02ff154f0883be55efb47380578c3b1c7c953f18b4ab8dd2ad9325af556ce8b92134e2733e7f14472a0d0e29ea6b763c3868c
7
+ data.tar.gz: 516169086976ad9770c374f0fb481f2b12c6c8cd04b5688e6752f7c72110bd76dd3b459be1d64915829582e1c701d1d0633ae6a726125db296ceaa1731938215
@@ -0,0 +1,2 @@
1
+
2
+ issuehunt: yuki-inoue
@@ -0,0 +1,29 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.7.1
18
+ # https://github.com/actions/cache/blob/master/examples.md#ruby---bundler
19
+ - uses: actions/cache@v1
20
+ with:
21
+ path: vendor/bundle
22
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
23
+ restore-keys: |
24
+ ${{ runner.os }}-gems-
25
+ - name: Build and test with Rake
26
+ run: |
27
+ gem install bundler
28
+ bundle install --jobs 4 --retry 3 --path vendor/bundle
29
+ bundle exec rubocop
data/.gitignore CHANGED
@@ -6,5 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- /Gemfile.lock
10
9
  /vendor
@@ -0,0 +1,20 @@
1
+ Metrics/LineLength:
2
+ Max: 160
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/ClassAndModuleChildren:
8
+ Enabled: false
9
+
10
+ Metrics/AbcSize:
11
+ Max: 100
12
+
13
+ Metrics/MethodLength:
14
+ Max: 60
15
+
16
+ Style/MultilineTernaryOperator:
17
+ Enabled: false
18
+
19
+ Lint/SuppressedException:
20
+ 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
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jupyter_on_rails (0.7.0)
5
+ daru
6
+ iruby
7
+ railties
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (6.0.3)
13
+ actionview (= 6.0.3)
14
+ activesupport (= 6.0.3)
15
+ rack (~> 2.0, >= 2.0.8)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
+ actionview (6.0.3)
20
+ activesupport (= 6.0.3)
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.0.3)
26
+ concurrent-ruby (~> 1.0, >= 1.0.2)
27
+ i18n (>= 0.7, < 2)
28
+ minitest (~> 5.1)
29
+ tzinfo (~> 1.1)
30
+ zeitwerk (~> 2.2, >= 2.2.2)
31
+ addressable (2.7.0)
32
+ public_suffix (>= 2.0.2, < 5.0)
33
+ ast (2.4.0)
34
+ backports (3.17.1)
35
+ bond (0.5.1)
36
+ builder (3.2.4)
37
+ bump (0.9.0)
38
+ concurrent-ruby (1.1.6)
39
+ crass (1.0.6)
40
+ daru (0.2.2)
41
+ backports
42
+ packable (~> 1.3.9)
43
+ data_uri (0.1.0)
44
+ erubi (1.9.0)
45
+ faraday (1.0.1)
46
+ multipart-post (>= 1.2, < 3)
47
+ faraday-http-cache (2.2.0)
48
+ faraday (>= 0.8)
49
+ github_changelog_generator (1.15.2)
50
+ activesupport
51
+ faraday-http-cache
52
+ multi_json
53
+ octokit (~> 4.6)
54
+ rainbow (>= 2.2.1)
55
+ rake (>= 10.0)
56
+ retriable (~> 3.0)
57
+ i18n (1.8.2)
58
+ concurrent-ruby (~> 1.0)
59
+ iruby (0.4.0)
60
+ bond (~> 0.5)
61
+ data_uri (~> 0.1)
62
+ mimemagic (~> 0.3)
63
+ multi_json (~> 1.11)
64
+ loofah (2.5.0)
65
+ crass (~> 1.0.2)
66
+ nokogiri (>= 1.5.9)
67
+ method_source (1.0.0)
68
+ mimemagic (0.3.5)
69
+ mini_portile2 (2.4.0)
70
+ minitest (5.14.0)
71
+ multi_json (1.14.1)
72
+ multipart-post (2.1.1)
73
+ nokogiri (1.10.9)
74
+ mini_portile2 (~> 2.4.0)
75
+ octokit (4.18.0)
76
+ faraday (>= 0.9)
77
+ sawyer (~> 0.8.0, >= 0.5.3)
78
+ packable (1.3.13)
79
+ backports
80
+ parallel (1.19.1)
81
+ parser (2.7.1.2)
82
+ ast (~> 2.4.0)
83
+ public_suffix (4.0.5)
84
+ rack (2.2.2)
85
+ rack-test (1.1.0)
86
+ rack (>= 1.0, < 3)
87
+ rails-dom-testing (2.0.3)
88
+ activesupport (>= 4.2.0)
89
+ nokogiri (>= 1.6)
90
+ rails-html-sanitizer (1.3.0)
91
+ loofah (~> 2.3)
92
+ railties (6.0.3)
93
+ actionpack (= 6.0.3)
94
+ activesupport (= 6.0.3)
95
+ method_source
96
+ rake (>= 0.8.7)
97
+ thor (>= 0.20.3, < 2.0)
98
+ rainbow (3.0.0)
99
+ rake (13.0.1)
100
+ retriable (3.1.2)
101
+ rexml (3.2.4)
102
+ rubocop (0.83.0)
103
+ parallel (~> 1.10)
104
+ parser (>= 2.7.0.1)
105
+ rainbow (>= 2.2.2, < 4.0)
106
+ rexml
107
+ ruby-progressbar (~> 1.7)
108
+ unicode-display_width (>= 1.4.0, < 2.0)
109
+ ruby-progressbar (1.10.1)
110
+ sawyer (0.8.2)
111
+ addressable (>= 2.3.5)
112
+ faraday (> 0.8, < 2.0)
113
+ thor (1.0.1)
114
+ thread_safe (0.3.6)
115
+ tzinfo (1.2.7)
116
+ thread_safe (~> 0.1)
117
+ unicode-display_width (1.7.0)
118
+ zeitwerk (2.3.0)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bump
125
+ github_changelog_generator
126
+ jupyter_on_rails!
127
+ rake
128
+ rubocop
129
+
130
+ BUNDLED WITH
131
+ 2.1.4
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
@@ -58,16 +58,18 @@ rake jupyter:notebook
58
58
  Eventually, you'll have jupyter opened, and the kernel being available.
59
59
 
60
60
 
61
- ### ApplicationRecord#to_df
61
+ ### ApplicationRecord.to_df/#to_df
62
62
 
63
63
  ```ruby
64
64
  User.to_df # => Daru::DataFrame is returned
65
+ user.to_df # => Daru::DataFrame for single record
65
66
  ```
66
67
 
67
68
  ### Daru::DataFrame#write_model
68
69
 
69
70
  For each row, call `to_h` and pass it to `model.new`.
70
- And then, imports them using `model.import`.
71
+ And then, imports them using `model.insert_all` on Rails >= 6, or `model.import` (requires adding
72
+ `activerecord-import` to your `Gemfile`).
71
73
 
72
74
  ```ruby
73
75
  df.write_model(User)
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
@@ -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,50 +1,50 @@
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)/}) }
35
+ .reject { |f| f.match(/\.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 "bundler", "~> 1.17"
41
- spec.add_development_dependency "rake", "~> 10.0"
42
- spec.add_development_dependency 'github_changelog_generator'
43
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'
44
45
 
45
46
  spec.add_dependency 'iruby'
46
47
  spec.add_dependency 'railties'
47
48
 
48
- spec.add_dependency 'activerecord-import'
49
49
  spec.add_dependency 'daru'
50
50
  end
@@ -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,17 @@ module JupyterOnRails
5
7
  module ActiveRecordExt
6
8
  extend ::ActiveSupport::Concern
7
9
 
10
+ # Rails 4.0 support
11
+ unless respond_to?(:class_methods)
12
+ def self.class_methods(&class_methods_module_definition)
13
+ mod = const_defined?(:ClassMethods, false) ?
14
+ const_get(:ClassMethods) :
15
+ const_set(:ClassMethods, Module.new)
16
+
17
+ mod.module_eval(&class_methods_module_definition)
18
+ end
19
+ end
20
+
8
21
  class_methods do
9
22
  def to_df
10
23
  relation = all
@@ -34,6 +47,10 @@ module JupyterOnRails
34
47
  ::Daru::DataFrame.new(datas)
35
48
  end
36
49
  end
50
+
51
+ def to_df
52
+ ::Daru::DataFrame.new([attributes])
53
+ end
37
54
  end
38
55
  end
39
56
  end
@@ -1,11 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JupyterOnRails
2
4
  module Daru
3
5
  module DataFrameExt
4
6
  def write_model(model)
5
- require 'activerecord-import'
7
+ if ActiveRecord.version >= Gem::Version.new('6.0.0.beta1')
8
+ write_model_rails(model)
9
+ else
10
+ write_model_activerecord_import(model)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def write_model_activerecord_import(model)
17
+ begin
18
+ require 'activerecord-import'
19
+ rescue LoadError
20
+ raise 'write_model requires either Rails >= 6 or the activerecord-import gem'
21
+ end
22
+
23
+ records = map_rows(&:to_h).map(&model.method(:new))
24
+ model.import(records)
25
+ end
6
26
 
7
- objs = map_rows(&:to_h).map(&model.method(:new))
8
- model.import(objs)
27
+ def write_model_rails(model)
28
+ model.insert_all(map_rows(&:to_h))
9
29
  end
10
30
  end
11
31
  end
@@ -1,17 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JupyterOnRails
2
4
  module IRubyKernelExtention
3
5
  class << self
4
- attr_accessor :root
6
+ attr_accessor :root, :sandbox
5
7
  end
6
8
 
7
9
  def run
10
+ # Load Daru extensions
11
+ begin
12
+ require 'daru'
13
+ require 'active_record'
14
+ rescue LoadError
15
+ else
16
+ require 'jupyter_on_rails/daru/active_record_ext'
17
+ require 'jupyter_on_rails/daru/data_frame_ext'
18
+
19
+ ::ActiveRecord::Base.instance_eval do
20
+ include ::JupyterOnRails::Daru::ActiveRecordExt
21
+ end
22
+ ::Daru::DataFrame.instance_eval do
23
+ include ::JupyterOnRails::Daru::DataFrameExt
24
+ end
25
+ end
26
+
8
27
  original = Dir.pwd
9
28
  root = IRubyKernelExtention.root
10
29
  Dir.chdir root
11
- app_file = File.expand_path('config/application.rb', root)
30
+ app_file = File.expand_path('config/environment.rb', root)
12
31
  require app_file
13
32
  Rails.application.require_environment!
14
33
  Dir.chdir original
34
+
35
+ if IRubyKernelExtention.sandbox
36
+ ActiveRecord::Base.connection.begin_transaction(joinable: false)
37
+
38
+ at_exit do
39
+ ActiveRecord::Base.connection.rollback_transaction
40
+ end
41
+ end
42
+
15
43
  super
16
44
  end
17
45
  end
@@ -0,0 +1,31 @@
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 'iruby_kernel_extention'
24
+ JupyterOnRails::IRubyKernelExtention.root = @root
25
+ JupyterOnRails::IRubyKernelExtention.sandbox = @sandbox
26
+
27
+ require 'iruby'
28
+ IRuby::Kernel.instance_eval { prepend JupyterOnRails::IRubyKernelExtention }
29
+ end
30
+ end
31
+ 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,46 @@
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
- ipython_dir = ENV['IPYTHONDIR'] || root / '.ipython'
22
+ ipython_dir = ENV['JUPYTER_DATA_DIR'] || ENV['IPYTHONDIR'] || root / '.ipython'
9
23
  ipython_dir = File.absolute_path(ipython_dir.to_s)
10
24
 
11
- sh "bundle exec iruby register --force --ipython-dir=#{Shellwords.shellescape(ipython_dir.to_s)}"
25
+ sh "JUPYTER_DATA_DIR=#{Shellwords.shellescape(ipython_dir.to_s)} bundle exec iruby register --force"
12
26
 
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"
27
+ [
28
+ OpenStruct.new(kernel_name: 'rails', boot_file: '../boot.rb', name_ext: ''),
29
+ OpenStruct.new(kernel_name: 'rails-sandbox', boot_file: '../boot_sandbox.rb', name_ext: ', sandbox')
30
+ ].each do |cfg|
31
+ sh "rm -rf #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/#{cfg.kernel_name}"
15
32
 
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
33
+ sh "cp -r #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/ruby #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/#{cfg.kernel_name}"
22
34
 
23
- File.write(kernel_file, JSON.dump(kernel_h))
35
+ kernel_file = File.expand_path("kernels/#{cfg.kernel_name}/kernel.json", ipython_dir.to_s)
36
+ kernel_h = JSON.parse(File.read(kernel_file))
37
+ kernel_h['argv'] << File.expand_path(cfg.boot_file, __dir__)
38
+ kernel_h['display_name'] = "#{Rails.application.class.parent} (rails #{Rails.version}#{cfg.name_ext})"
39
+ kernel_h['env'] ||= {}
40
+ kernel_h['env']['RAILS_ROOT'] = root.to_s
24
41
 
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)
42
+ File.write(kernel_file, JSON.dump(kernel_h))
43
+ end
29
44
  end
30
45
  end
46
+ # rubocop:enable Metrics/BlockLength
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JupyterOnRails
2
- VERSION = '0.5.3'
4
+ VERSION = '0.7.0'
3
5
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jupyter_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki INOUE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-21 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
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
14
+ name: bump
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: github_changelog_generator
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +39,7 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: bump
42
+ name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
@@ -67,13 +53,13 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: iruby
56
+ name: rubocop
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
- type: :runtime
62
+ type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
@@ -81,7 +67,7 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: railties
70
+ name: iruby
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: activerecord-import
84
+ name: railties
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
@@ -129,9 +115,14 @@ executables: []
129
115
  extensions: []
130
116
  extra_rdoc_files: []
131
117
  files:
118
+ - ".github/FUNDING.yml"
119
+ - ".github/workflows/ruby.yml"
132
120
  - ".gitignore"
121
+ - ".rubocop.yml"
133
122
  - CHANGELOG.md
134
123
  - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE
135
126
  - README.md
136
127
  - Rakefile
137
128
  - bin/console
@@ -139,9 +130,11 @@ files:
139
130
  - jupyter_on_rails.gemspec
140
131
  - lib/jupyter_on_rails.rb
141
132
  - lib/jupyter_on_rails/boot.rb
133
+ - lib/jupyter_on_rails/boot_sandbox.rb
142
134
  - lib/jupyter_on_rails/daru/active_record_ext.rb
143
135
  - lib/jupyter_on_rails/daru/data_frame_ext.rb
144
136
  - lib/jupyter_on_rails/iruby_kernel_extention.rb
137
+ - lib/jupyter_on_rails/kernel.rb
145
138
  - lib/jupyter_on_rails/railtie.rb
146
139
  - lib/jupyter_on_rails/railtie/jupyter.rake
147
140
  - lib/jupyter_on_rails/version.rb