jupyter_on_rails 0.10.0 → 0.13.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: 84b32009995240fae40e2d80e6a68039ed673f69fe96817b12351e2ee68ef379
4
- data.tar.gz: 0bf6f03122bfbe572a61cefb2fbda365bda43e935c199a38fa0e8c2780a9f991
3
+ metadata.gz: 825a6e5e99d4d99d2efc6a11878e1491fcca63fcb551c1d1ad1c209fbada3d41
4
+ data.tar.gz: e2dd4b956fb8fe643c9bdaaba7bf5676d69fa45c6dc2618fb5ee54801089db26
5
5
  SHA512:
6
- metadata.gz: 0ae8424810f441ce8b5aac30a7fce4333a20309fe02b5eee48675c7b1968a74b50b5b5afbaf36019c25c1165f625d6659fa0b7a7f38872d6c1b212d0d66e5b33
7
- data.tar.gz: 3c54d670bbd7961a0f82a7e5786e8240d00e3ea28ca5ec372015db907f9ef94b615465d97bb7037053a5b8bfcc178539ef0422a379e0775102eb2f1acbaf1470
6
+ metadata.gz: 47a6707a1a8763e9452d0f7482647fe5cbb2092bb0730a8a16bbea397e6c211a5803c3cacf5668f556f1ba931739144beb50780a5b87b24d82e9e919cf5fc4f1
7
+ data.tar.gz: e621139221f8ac2c8dd50e711ac0f745928e3a43662ceb515184fef21994c4b191fd5fef5461541e4ff7016943fe79af74bd45b050a129bb5b8c43685f71dba9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jupyter_on_rails (0.10.0)
4
+ jupyter_on_rails (0.13.0)
5
5
  daru
6
6
  iruby
7
7
  railties
@@ -9,25 +9,24 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (6.1.4.1)
13
- actionview (= 6.1.4.1)
14
- activesupport (= 6.1.4.1)
15
- rack (~> 2.0, >= 2.0.9)
12
+ actionpack (7.0.2.4)
13
+ actionview (= 7.0.2.4)
14
+ activesupport (= 7.0.2.4)
15
+ rack (~> 2.0, >= 2.2.0)
16
16
  rack-test (>= 0.6.3)
17
17
  rails-dom-testing (~> 2.0)
18
18
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
- actionview (6.1.4.1)
20
- activesupport (= 6.1.4.1)
19
+ actionview (7.0.2.4)
20
+ activesupport (= 7.0.2.4)
21
21
  builder (~> 3.1)
22
22
  erubi (~> 1.4)
23
23
  rails-dom-testing (~> 2.0)
24
24
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
25
- activesupport (6.1.4.1)
25
+ activesupport (7.0.2.4)
26
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
27
27
  i18n (>= 1.6, < 2)
28
28
  minitest (>= 5.1)
29
29
  tzinfo (~> 2.0)
30
- zeitwerk (~> 2.3)
31
30
  addressable (2.8.0)
32
31
  public_suffix (>= 2.0.2, < 5.0)
33
32
  ast (2.4.2)
@@ -49,10 +48,10 @@ GEM
49
48
  async (~> 1.14)
50
49
  async-pool (0.3.6)
51
50
  async (~> 1.25)
52
- backports (3.21.0)
51
+ backports (3.23.0)
53
52
  builder (3.2.4)
54
53
  bump (0.10.0)
55
- concurrent-ruby (1.1.9)
54
+ concurrent-ruby (1.1.10)
56
55
  console (1.12.0)
57
56
  fiber-local
58
57
  crass (1.0.6)
@@ -75,7 +74,7 @@ GEM
75
74
  faraday (>= 0.8)
76
75
  faraday-net_http (1.0.1)
77
76
  faraday-net_http_persistent (1.1.0)
78
- ffi (1.15.4)
77
+ ffi (1.15.5)
79
78
  ffi-rzmq (2.0.7)
80
79
  ffi-rzmq-core (>= 1.0.7)
81
80
  ffi-rzmq-core (1.0.7)
@@ -91,11 +90,11 @@ GEM
91
90
  rainbow (>= 2.2.1)
92
91
  rake (>= 10.0)
93
92
  retriable (~> 3.0)
94
- i18n (1.8.10)
93
+ i18n (1.10.0)
95
94
  concurrent-ruby (~> 1.0)
96
- io-console (0.5.9)
97
- irb (1.3.7)
98
- reline (>= 0.2.7)
95
+ io-console (0.5.11)
96
+ irb (1.4.1)
97
+ reline (>= 0.3.0)
99
98
  iruby (0.7.4)
100
99
  data_uri (~> 0.1)
101
100
  ffi-rzmq
@@ -103,21 +102,21 @@ GEM
103
102
  mime-types (>= 3.3.1)
104
103
  multi_json (~> 1.11)
105
104
  native-package-installer
106
- loofah (2.12.0)
105
+ loofah (2.18.0)
107
106
  crass (~> 1.0.2)
108
107
  nokogiri (>= 1.5.9)
109
108
  method_source (1.0.0)
110
109
  mime-types (3.4.1)
111
110
  mime-types-data (~> 3.2015)
112
- mime-types-data (3.2021.1115)
113
- mini_portile2 (2.6.1)
114
- minitest (5.14.4)
111
+ mime-types-data (3.2022.0105)
112
+ mini_portile2 (2.8.0)
113
+ minitest (5.15.0)
115
114
  multi_json (1.15.0)
116
115
  multipart-post (2.1.1)
117
- native-package-installer (1.1.1)
116
+ native-package-installer (1.1.4)
118
117
  nio4r (2.5.7)
119
- nokogiri (1.12.5)
120
- mini_portile2 (~> 2.6.1)
118
+ nokogiri (1.13.6)
119
+ mini_portile2 (~> 2.8.0)
121
120
  racc (~> 1.4)
122
121
  octokit (4.21.0)
123
122
  faraday (>= 0.9)
@@ -144,16 +143,17 @@ GEM
144
143
  nokogiri (>= 1.6)
145
144
  rails-html-sanitizer (1.4.2)
146
145
  loofah (~> 2.3)
147
- railties (6.1.4.1)
148
- actionpack (= 6.1.4.1)
149
- activesupport (= 6.1.4.1)
146
+ railties (7.0.2.4)
147
+ actionpack (= 7.0.2.4)
148
+ activesupport (= 7.0.2.4)
150
149
  method_source
151
- rake (>= 0.13)
150
+ rake (>= 12.2)
152
151
  thor (~> 1.0)
152
+ zeitwerk (~> 2.5)
153
153
  rainbow (3.0.0)
154
154
  rake (13.0.3)
155
155
  regexp_parser (2.1.1)
156
- reline (0.2.7)
156
+ reline (0.3.1)
157
157
  io-console (~> 0.5)
158
158
  retriable (3.1.2)
159
159
  rexml (3.2.5)
@@ -173,12 +173,12 @@ GEM
173
173
  sawyer (0.8.2)
174
174
  addressable (>= 2.3.5)
175
175
  faraday (> 0.8, < 2.0)
176
- thor (1.1.0)
176
+ thor (1.2.1)
177
177
  timers (4.3.3)
178
178
  tzinfo (2.0.4)
179
179
  concurrent-ruby (~> 1.0)
180
180
  unicode-display_width (2.0.0)
181
- zeitwerk (2.4.2)
181
+ zeitwerk (2.5.4)
182
182
 
183
183
  PLATFORMS
184
184
  ruby
@@ -1,34 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JupyterOnRails
4
- module Initializer
5
- def self.run(root:, sandbox:)
6
- # Load Daru extensions
7
- begin
4
+ class Initializer
5
+ def self.run(**opts)
6
+ new(**opts).run
7
+ end
8
+
9
+ def initialize(root:, sandbox:)
10
+ @root = root
11
+ @sandbox = sandbox
12
+ end
13
+
14
+ attr_reader :root, :sandbox
15
+
16
+ def run
17
+ setup_daru
18
+ load_rails_environment
19
+ setup_console_methods
20
+ setup_sandbox_transaction if sandbox
21
+ end
22
+
23
+ def setup_daru
24
+ require 'active_support/lazy_load_hooks'
25
+
26
+ ActiveSupport.on_load(:active_record) do
27
+ # Load Daru extensions
28
+
8
29
  require 'daru'
9
- require 'active_record'
10
30
  rescue LoadError
11
31
  else
12
32
  require 'jupyter_on_rails/daru/active_record_ext'
13
33
  require 'jupyter_on_rails/daru/data_frame_ext'
14
34
 
15
- ::ActiveRecord::Base.instance_eval do
16
- include ::JupyterOnRails::Daru::ActiveRecordExt
17
- end
35
+ include ::JupyterOnRails::Daru::ActiveRecordExt
36
+
18
37
  ::Daru::DataFrame.instance_eval do
19
38
  include ::JupyterOnRails::Daru::DataFrameExt
20
39
  end
40
+
41
+ IRuby::Display::Registry.instance_eval do
42
+ match do |obj|
43
+ obj.is_a?(ActiveRecord::Relation) ||
44
+ obj.is_a?(::Class) && obj < ActiveRecord::Base && !obj.abstract_class
45
+ end
46
+ priority 100
47
+ format 'text/html' do |obj|
48
+ n = 10
49
+ puts "finding top #{n}"
50
+ obj.limit(n).to_df.to_html
51
+ end
52
+ end
21
53
  end
54
+ end
22
55
 
23
- original = Dir.pwd
24
- Dir.chdir root
56
+ def load_rails_environment
25
57
  app_file = File.expand_path('config/environment.rb', root)
26
- require app_file
27
- Rails.application.require_environment!
28
- Dir.chdir original
58
+ Dir.chdir(root) do
59
+ require app_file
60
+ end
61
+ end
29
62
 
30
- return unless sandbox
63
+ def setup_console_methods
64
+ require 'rails/console/app'
65
+ IRuby::Kernel
66
+ .instance
67
+ .instance_variable_get(:@backend)
68
+ .instance_variable_get(:@main)
69
+ .extend(Rails::ConsoleMethods)
70
+ end
31
71
 
72
+ def setup_sandbox_transaction
32
73
  ActiveRecord::Base.connection.begin_transaction(joinable: false)
33
74
  at_exit do
34
75
  ActiveRecord::Base.connection.rollback_transaction
@@ -26,19 +26,6 @@ module JupyterOnRails
26
26
  IRuby::Kernel.events.register(:initialized) do |_kernel|
27
27
  JupyterOnRails::Initializer.run(root: @root, sandbox: @sandbox)
28
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
29
  end
43
30
  end
44
31
  end
@@ -6,12 +6,11 @@ require 'ostruct'
6
6
 
7
7
  # rubocop:disable Metrics/BlockLength
8
8
  namespace :jupyter do
9
- desc 'start jupyter notebook'
10
- task notebook: :install_kernels do
9
+ exec_jupyter_command = lambda do |subcomand|
11
10
  ipython_dir = ENV['IPYTHONDIR'] || Rails.root / '.ipython'
12
11
 
13
12
  env = { 'JUPYTER_DATA_DIR' => ipython_dir.to_s }
14
- commands = %w[jupyter notebook]
13
+ commands = ['jupyter', subcomand]
15
14
 
16
15
  if (Rails.root / 'pyproject.toml').exist?
17
16
  commands = %w[poetry run] + commands
@@ -22,6 +21,16 @@ namespace :jupyter do
22
21
  Process.exec(env, *commands)
23
22
  end
24
23
 
24
+ desc 'start jupyter notebook'
25
+ task notebook: :install_kernels do
26
+ instance_exec('notebook', &exec_jupyter_command)
27
+ end
28
+
29
+ desc 'start jupyter lab'
30
+ task lab: :install_kernels do
31
+ instance_exec('lab', &exec_jupyter_command)
32
+ end
33
+
25
34
  desc 'Install the kernel'
26
35
  task :install_kernels do
27
36
  root = Rails.root
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JupyterOnRails
4
- VERSION = '0.10.0'
4
+ VERSION = '0.13.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jupyter_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.13.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: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.2.32
159
+ rubygems_version: 3.1.6
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Integrate jupyter into rails