jupyter_on_rails 0.7.0 → 0.10.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: d4dd954da8ae0ebe5bad32d7b98acb1dbde79b0f3b6bcd837d019f11085b50f8
4
- data.tar.gz: 992c4ab71f53ba0b59752558e7cbaf932de72e9d6db4ac38a4ab5bef595b655c
3
+ metadata.gz: 84b32009995240fae40e2d80e6a68039ed673f69fe96817b12351e2ee68ef379
4
+ data.tar.gz: 0bf6f03122bfbe572a61cefb2fbda365bda43e935c199a38fa0e8c2780a9f991
5
5
  SHA512:
6
- metadata.gz: 48132a0169aad90d07c55297efe02ff154f0883be55efb47380578c3b1c7c953f18b4ab8dd2ad9325af556ce8b92134e2733e7f14472a0d0e29ea6b763c3868c
7
- data.tar.gz: 516169086976ad9770c374f0fb481f2b12c6c8cd04b5688e6752f7c72110bd76dd3b459be1d64915829582e1c701d1d0633ae6a726125db296ceaa1731938215
6
+ metadata.gz: 0ae8424810f441ce8b5aac30a7fce4333a20309fe02b5eee48675c7b1968a74b50b5b5afbaf36019c25c1165f625d6659fa0b7a7f38872d6c1b212d0d66e5b33
7
+ data.tar.gz: 3c54d670bbd7961a0f82a7e5786e8240d00e3ea28ca5ec372015db907f9ef94b615465d97bb7037053a5b8bfcc178539ef0422a379e0775102eb2f1acbaf1470
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ Gemspec/RequiredRubyVersion:
2
+ Enabled: false
3
+
1
4
  Metrics/LineLength:
2
5
  Max: 160
3
6
 
@@ -13,6 +16,12 @@ Metrics/AbcSize:
13
16
  Metrics/MethodLength:
14
17
  Max: 60
15
18
 
19
+ Metrics/PerceivedComplexity:
20
+ Max: 20
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 20
24
+
16
25
  Style/MultilineTernaryOperator:
17
26
  Enabled: false
18
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jupyter_on_rails (0.7.0)
4
+ jupyter_on_rails (0.10.0)
5
5
  daru
6
6
  iruby
7
7
  railties
@@ -9,113 +9,176 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (6.0.3)
13
- actionview (= 6.0.3)
14
- activesupport (= 6.0.3)
15
- rack (~> 2.0, >= 2.0.8)
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)
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.0.3)
20
- activesupport (= 6.0.3)
19
+ actionview (6.1.4.1)
20
+ activesupport (= 6.1.4.1)
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.0.3)
25
+ activesupport (6.1.4.1)
26
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)
27
+ i18n (>= 1.6, < 2)
28
+ minitest (>= 5.1)
29
+ tzinfo (~> 2.0)
30
+ zeitwerk (~> 2.3)
31
+ addressable (2.8.0)
32
32
  public_suffix (>= 2.0.2, < 5.0)
33
- ast (2.4.0)
34
- backports (3.17.1)
35
- bond (0.5.1)
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)
36
53
  builder (3.2.4)
37
- bump (0.9.0)
38
- concurrent-ruby (1.1.6)
54
+ bump (0.10.0)
55
+ concurrent-ruby (1.1.9)
56
+ console (1.12.0)
57
+ fiber-local
39
58
  crass (1.0.6)
40
- daru (0.2.2)
41
- backports
42
- packable (~> 1.3.9)
59
+ daru (0.3)
60
+ packable (~> 1.3.13)
43
61
  data_uri (0.1.0)
44
- erubi (1.9.0)
45
- faraday (1.0.1)
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)
46
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)
47
74
  faraday-http-cache (2.2.0)
48
75
  faraday (>= 0.8)
49
- github_changelog_generator (1.15.2)
76
+ faraday-net_http (1.0.1)
77
+ faraday-net_http_persistent (1.1.0)
78
+ ffi (1.15.4)
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)
50
85
  activesupport
86
+ async (>= 1.25.0)
87
+ async-http-faraday
51
88
  faraday-http-cache
52
89
  multi_json
53
90
  octokit (~> 4.6)
54
91
  rainbow (>= 2.2.1)
55
92
  rake (>= 10.0)
56
93
  retriable (~> 3.0)
57
- i18n (1.8.2)
94
+ i18n (1.8.10)
58
95
  concurrent-ruby (~> 1.0)
59
- iruby (0.4.0)
60
- bond (~> 0.5)
96
+ io-console (0.5.9)
97
+ irb (1.3.7)
98
+ reline (>= 0.2.7)
99
+ iruby (0.7.4)
61
100
  data_uri (~> 0.1)
62
- mimemagic (~> 0.3)
101
+ ffi-rzmq
102
+ irb
103
+ mime-types (>= 3.3.1)
63
104
  multi_json (~> 1.11)
64
- loofah (2.5.0)
105
+ native-package-installer
106
+ loofah (2.12.0)
65
107
  crass (~> 1.0.2)
66
108
  nokogiri (>= 1.5.9)
67
109
  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)
110
+ mime-types (3.4.1)
111
+ mime-types-data (~> 3.2015)
112
+ mime-types-data (3.2021.1115)
113
+ mini_portile2 (2.6.1)
114
+ minitest (5.14.4)
115
+ multi_json (1.15.0)
72
116
  multipart-post (2.1.1)
73
- nokogiri (1.10.9)
74
- mini_portile2 (~> 2.4.0)
75
- octokit (4.18.0)
117
+ native-package-installer (1.1.1)
118
+ nio4r (2.5.7)
119
+ nokogiri (1.12.5)
120
+ mini_portile2 (~> 2.6.1)
121
+ racc (~> 1.4)
122
+ octokit (4.21.0)
76
123
  faraday (>= 0.9)
77
124
  sawyer (~> 0.8.0, >= 0.5.3)
78
- packable (1.3.13)
125
+ packable (1.3.15)
79
126
  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)
127
+ parallel (1.20.1)
128
+ parser (3.0.1.1)
129
+ ast (~> 2.4.1)
130
+ protocol-hpack (1.4.2)
131
+ protocol-http (0.22.0)
132
+ protocol-http1 (0.14.1)
133
+ protocol-http (~> 0.22)
134
+ protocol-http2 (0.14.2)
135
+ protocol-hpack (~> 1.4)
136
+ protocol-http (~> 0.18)
137
+ public_suffix (4.0.6)
138
+ racc (1.6.0)
139
+ rack (2.2.3)
85
140
  rack-test (1.1.0)
86
141
  rack (>= 1.0, < 3)
87
142
  rails-dom-testing (2.0.3)
88
143
  activesupport (>= 4.2.0)
89
144
  nokogiri (>= 1.6)
90
- rails-html-sanitizer (1.3.0)
145
+ rails-html-sanitizer (1.4.2)
91
146
  loofah (~> 2.3)
92
- railties (6.0.3)
93
- actionpack (= 6.0.3)
94
- activesupport (= 6.0.3)
147
+ railties (6.1.4.1)
148
+ actionpack (= 6.1.4.1)
149
+ activesupport (= 6.1.4.1)
95
150
  method_source
96
- rake (>= 0.8.7)
97
- thor (>= 0.20.3, < 2.0)
151
+ rake (>= 0.13)
152
+ thor (~> 1.0)
98
153
  rainbow (3.0.0)
99
- rake (13.0.1)
154
+ rake (13.0.3)
155
+ regexp_parser (2.1.1)
156
+ reline (0.2.7)
157
+ io-console (~> 0.5)
100
158
  retriable (3.1.2)
101
- rexml (3.2.4)
102
- rubocop (0.83.0)
159
+ rexml (3.2.5)
160
+ rubocop (1.15.0)
103
161
  parallel (~> 1.10)
104
- parser (>= 2.7.0.1)
162
+ parser (>= 3.0.0.0)
105
163
  rainbow (>= 2.2.2, < 4.0)
164
+ regexp_parser (>= 1.8, < 3.0)
106
165
  rexml
166
+ rubocop-ast (>= 1.5.0, < 2.0)
107
167
  ruby-progressbar (~> 1.7)
108
- unicode-display_width (>= 1.4.0, < 2.0)
109
- ruby-progressbar (1.10.1)
168
+ unicode-display_width (>= 1.4.0, < 3.0)
169
+ rubocop-ast (1.6.0)
170
+ parser (>= 3.0.1.1)
171
+ ruby-progressbar (1.11.0)
172
+ ruby2_keywords (0.0.4)
110
173
  sawyer (0.8.2)
111
174
  addressable (>= 2.3.5)
112
175
  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)
176
+ thor (1.1.0)
177
+ timers (4.3.3)
178
+ tzinfo (2.0.4)
179
+ concurrent-ruby (~> 1.0)
180
+ unicode-display_width (2.0.0)
181
+ zeitwerk (2.4.2)
119
182
 
120
183
  PLATFORMS
121
184
  ruby
@@ -128,4 +191,4 @@ DEPENDENCIES
128
191
  rubocop
129
192
 
130
193
  BUNDLED WITH
131
- 2.1.4
194
+ 2.2.22
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
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
32
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
33
  `git ls-files -z`.split("\x0")
34
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
35
- .reject { |f| f.match(/\.png$/) }
34
+ .reject { |f| f.match(%r{^(test|spec|features|\.github)/}) }
35
+ .reject { |f| f.match(/(\.gitignore|\.png)$/) }
36
36
  end
37
37
  spec.bindir = 'exe'
38
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JupyterOnRails
4
- module IRubyKernelExtention
5
- class << self
6
- attr_accessor :root, :sandbox
7
- end
8
-
9
- def run
4
+ module Initializer
5
+ def self.run(root:, sandbox:)
10
6
  # Load Daru extensions
11
7
  begin
12
8
  require 'daru'
@@ -25,22 +21,18 @@ module JupyterOnRails
25
21
  end
26
22
 
27
23
  original = Dir.pwd
28
- root = IRubyKernelExtention.root
29
24
  Dir.chdir root
30
25
  app_file = File.expand_path('config/environment.rb', root)
31
26
  require app_file
32
27
  Rails.application.require_environment!
33
28
  Dir.chdir original
34
29
 
35
- if IRubyKernelExtention.sandbox
36
- ActiveRecord::Base.connection.begin_transaction(joinable: false)
30
+ return unless sandbox
37
31
 
38
- at_exit do
39
- ActiveRecord::Base.connection.rollback_transaction
40
- end
32
+ ActiveRecord::Base.connection.begin_transaction(joinable: false)
33
+ at_exit do
34
+ ActiveRecord::Base.connection.rollback_transaction
41
35
  end
42
-
43
- super
44
36
  end
45
37
  end
46
38
  end
@@ -20,12 +20,25 @@ module JupyterOnRails
20
20
  end
21
21
 
22
22
  def load_extensions
23
- require_relative 'iruby_kernel_extention'
24
- JupyterOnRails::IRubyKernelExtention.root = @root
25
- JupyterOnRails::IRubyKernelExtention.sandbox = @sandbox
23
+ require_relative 'initializer'
26
24
 
27
25
  require 'iruby'
28
- IRuby::Kernel.instance_eval { prepend JupyterOnRails::IRubyKernelExtention }
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
29
42
  end
30
43
  end
31
44
  end
@@ -12,7 +12,13 @@ namespace :jupyter do
12
12
 
13
13
  env = { 'JUPYTER_DATA_DIR' => ipython_dir.to_s }
14
14
  commands = %w[jupyter notebook]
15
- commands = %w[pipenv run] + commands if (Rails.root / 'Pipfile').exist?
15
+
16
+ if (Rails.root / 'pyproject.toml').exist?
17
+ commands = %w[poetry run] + commands
18
+ elsif (Rails.root / 'Pipfile').exist?
19
+ commands = %w[pipenv run] + commands
20
+ end
21
+
16
22
  Process.exec(env, *commands)
17
23
  end
18
24
 
@@ -21,6 +27,12 @@ namespace :jupyter do
21
27
  root = Rails.root
22
28
  ipython_dir = ENV['JUPYTER_DATA_DIR'] || ENV['IPYTHONDIR'] || root / '.ipython'
23
29
  ipython_dir = File.absolute_path(ipython_dir.to_s)
30
+ application_module =
31
+ if Rails::VERSION::MAJOR >= 6
32
+ Rails.application.class.module_parent
33
+ else
34
+ Rails.application.class.parent
35
+ end
24
36
 
25
37
  sh "JUPYTER_DATA_DIR=#{Shellwords.shellescape(ipython_dir.to_s)} bundle exec iruby register --force"
26
38
 
@@ -35,7 +47,7 @@ namespace :jupyter do
35
47
  kernel_file = File.expand_path("kernels/#{cfg.kernel_name}/kernel.json", ipython_dir.to_s)
36
48
  kernel_h = JSON.parse(File.read(kernel_file))
37
49
  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})"
50
+ kernel_h['display_name'] = "#{application_module} (rails #{Rails.version}#{cfg.name_ext})"
39
51
  kernel_h['env'] ||= {}
40
52
  kernel_h['env']['RAILS_ROOT'] = root.to_s
41
53
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JupyterOnRails
4
- VERSION = '0.7.0'
4
+ VERSION = '0.10.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.7.0
4
+ version: 0.10.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-05-13 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -115,9 +115,6 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".github/FUNDING.yml"
119
- - ".github/workflows/ruby.yml"
120
- - ".gitignore"
121
118
  - ".rubocop.yml"
122
119
  - CHANGELOG.md
123
120
  - Gemfile
@@ -133,7 +130,7 @@ files:
133
130
  - lib/jupyter_on_rails/boot_sandbox.rb
134
131
  - lib/jupyter_on_rails/daru/active_record_ext.rb
135
132
  - lib/jupyter_on_rails/daru/data_frame_ext.rb
136
- - lib/jupyter_on_rails/iruby_kernel_extention.rb
133
+ - lib/jupyter_on_rails/initializer.rb
137
134
  - lib/jupyter_on_rails/kernel.rb
138
135
  - lib/jupyter_on_rails/railtie.rb
139
136
  - lib/jupyter_on_rails/railtie/jupyter.rake
@@ -144,7 +141,7 @@ metadata:
144
141
  allowed_push_host: https://rubygems.org
145
142
  homepage_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
146
143
  source_code_uri: https://github.com/Yuki-Inoue/jupyter_on_rails
147
- post_install_message:
144
+ post_install_message:
148
145
  rdoc_options: []
149
146
  require_paths:
150
147
  - lib
@@ -159,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
156
  - !ruby/object:Gem::Version
160
157
  version: '0'
161
158
  requirements: []
162
- rubygems_version: 3.0.3
163
- signing_key:
159
+ rubygems_version: 3.2.32
160
+ signing_key:
164
161
  specification_version: 4
165
162
  summary: Integrate jupyter into rails
166
163
  test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,2 +0,0 @@
1
-
2
- issuehunt: yuki-inoue
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /vendor