Sha256: 22d3aacb91f5857fbaef3d205e91ffa620a7ae7843a56bf2f46ba71cfcdf7dfb
Contents?: true
Size: 1.13 KB
Versions: 13
Compression:
Stored size: 1.13 KB
Contents
require 'shellwords' require 'json' namespace :jupyter do desc 'start jupyter notebook' task :notebook do root = Rails.root ipython_dir = ENV['IPYTHONDIR'] || root / '.ipython' ipython_dir = File.absolute_path(ipython_dir.to_s) sh "bundle exec iruby register --force --ipython-dir=#{Shellwords.shellescape(ipython_dir.to_s)}" sh "rm -rf #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/rails" sh "cp -r #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/ruby #{Shellwords.shellescape(ipython_dir.to_s)}/kernels/rails" kernel_file = File.expand_path('kernels/rails/kernel.json', ipython_dir.to_s) kernel_h = JSON.parse(File.read(kernel_file)) kernel_h['argv'] << File.expand_path('../boot.rb', __dir__) kernel_h['display_name'] = "#{Rails.application.class.parent} (rails #{Rails.version})" kernel_h['env'] ||= {} kernel_h['env']['RAILS_ROOT'] = root.to_s File.write(kernel_file, JSON.dump(kernel_h)) env = { 'IPYTHONDIR' => ipython_dir.to_s } commands = %w[jupyter notebook] commands = %w[pipenv run] + commands if (root / 'Pipfile').exist? Process.exec(env, *commands) end end
Version data entries
13 entries across 13 versions & 1 rubygems