iruby-dependencies 2.0.4 → 3.0.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
- SHA1:
3
- metadata.gz: 280b976207b3706948e35bf332b2545f3ee3b30c
4
- data.tar.gz: 8224d4654adcf62f648c61bbb03074cf3d451095
2
+ SHA256:
3
+ metadata.gz: 93eac5474a61ffd224821a9423743f211683c362693002c0ae970fbab4e0df0a
4
+ data.tar.gz: 0375f511e0d79f2e52fa5e678d22a9e85b8c1e695ffa4a5d8db730ccdb43804a
5
5
  SHA512:
6
- metadata.gz: 723dea17bcbb150a47179005b8bcfa6a064b1699a15a5aae9979978503e2183777bdec7abc36eab65dec5384ce70c00190f9c0a9d62f88fbcc70a7b54456e9bf
7
- data.tar.gz: 239d46655bdb6f8f413abd0099c1e00e68da199e4e300a43635de7f9d37ca5672d51b3c36ce250a24bc1127f5cca5574f6a67af9426733c513a1a0be5c8006c9
6
+ metadata.gz: 5a26e060f1a74f083fcfa074e8872f918ae254a152c32c30c815f84b0886c4f83d0af36a2fed25de7128fcd948fdfd9bd4600cfbd152ab4c8412fb7694b55cc3
7
+ data.tar.gz: aeb5d7547d3168b0ebbc9debb36438e04b8cd2212ad6c290ee8fcb45dc29c989ad597c4f4aebae573f57e643123b22cd8de9dc8a020ff97e67a04a281cec8b24
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # IRuby::Dependencies
2
2
 
3
- `IRuby::Dependencies` is a module for injecting Ruby dependencies into Jupyter Notebooks. For example,
3
+ `IRuby::Dependencies` is a thin wrapper around [bundler/inline](https://bundler.io/guides/bundler_in_a_single_file_ruby_script.html) for injecting Ruby dependencies into Jupyter Notebooks along with their system dependencies. For example,
4
4
 
5
5
  ```ruby
6
6
  require 'iruby/dependencies'
@@ -11,10 +11,6 @@ dependencies do
11
11
  end
12
12
  ```
13
13
 
14
- ## RubyGems Compatability
15
-
16
- There are issues with **rerunning** dependency blocks on machine with RubyGem versions greater than 2.4.5.1.
17
-
18
14
  ## Installation
19
15
 
20
16
  ```bash
@@ -23,16 +19,25 @@ $ gem install iruby-dependencies
23
19
 
24
20
  You'll have to restart any IRuby kernels already running.
25
21
 
26
- ## Usage
22
+ ## Configuration
27
23
 
28
- `IRuby::Dependencies` uses the [Bundler Gemfile syntax](http://bundler.io/v1.5/gemfile.html) with some additional methods:
24
+ Most Jupyter notebooks run in highly reproducible environments (e.g. Docker containers). An `IRuby::Dependencies` can be created that maps gems to the commands that must be executed before that gem can be installed. The config location should be saved as a [Bundler config](https://bundler.io/v2.1/bundle_config.html) with the key `dependencies.config`. The config location can be a local file path or URL. For example:
29
25
 
30
- | Method | Description |
31
- | ------ | ----------- |
32
- | `script <url>` | Loads the javascript at the given url into the notebook as a `script` tag |
33
- | `define <hash>` | Defines alternate paths for requirejs modules. Keys are modules, values are paths |
34
- | `exec <string>` | Executes the system command, for example `yum install gsl` |
35
- | `css <string>` | Loads the stylesheet at the given url into the notebook as a `link` tag
26
+ ```bash
27
+ $ bundle config dependencies.config /home/jovyan/dependencies.config
28
+ ```
29
+
30
+ RemThe config file itself is a JSON file that maps gem names to commands that should be executed before the gem is installed. For instance, in a CentOS/RHEL environment, the config entry would install the `gsl` YUM package before installing the `gsl` RubyGem:
31
+
32
+ ```json
33
+ {
34
+ 'gsl': [
35
+ ["exec", "yum install gsl"]
36
+ ]
37
+ }
38
+ ```
39
+
40
+ ## Usage
36
41
 
37
42
  To see the normal bundler output, pass `verbose: true` to the dependencies method:
38
43
 
@@ -41,8 +46,4 @@ dependencies verbose: true do
41
46
  gem 'http'
42
47
  gem 'addressable'
43
48
  end
44
- ```
45
-
46
- ## Active Gems
47
-
48
- When `IRuby::Dependencies` is first loaded, it saves a list of all active gems, which are added to the dependency bundle. For example, since IRuby uses multi_json, the multi_json gem is always included in the bundle. Active gems cannot be removed and their versions are fixed. If you need a different version of an active gem, install it on the command line and restart the kernel. To reduce the number of active gems, `require 'iruby/dependencies'` as early in your notebook as possible.
49
+ ```
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = IRuby::Dependencies::VERSION
9
9
  spec.authors = ["Kyle King"]
10
10
  spec.email = ["kylejking@gmail.com"]
11
+ spec.license = "MIT"
11
12
 
12
13
  spec.summary = %q{IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter Notebooks}
13
14
  spec.homepage = "https://github.com/jupyter-gallery/iruby-dependencies"
@@ -17,8 +18,9 @@ Gem::Specification.new do |spec|
17
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.add_dependency "iruby"
21
- spec.add_dependency "multi_json"
22
- spec.add_dependency "bundler", "~> 1.12"
23
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_dependency "iruby", "~> 0.4"
22
+ spec.add_dependency "bundler", "~> 2"
23
+
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rake"
24
26
  end
@@ -1,81 +1,78 @@
1
- require 'iruby/dependencies/dsl'
2
- require 'iruby/dependencies/config'
3
- require 'iruby/dependencies/unload'
4
- require 'iruby/dependencies/version'
5
-
6
- # require 'mypki' if requested so it is an active gem
7
- if Bundler.settings['dependencies.mypki']
8
- require 'mypki'
9
- require 'erector'
10
- end
1
+ require 'net/https'
2
+ require 'bundler/inline'
11
3
 
12
4
  module IRuby
13
- module Dependencies
14
- ACTIVE_GEMS = {}
15
-
16
- # activate default gems
17
- %w[bigdecimal io-console json psych rdoc].each {|g| gem g}
18
-
19
- # this code is taken from bundler/inline with small changes
20
- def self.dependencies verbose: false, &gemfile
21
- if ACTIVE_GEMS.empty?
22
- ACTIVE_GEMS.merge! Gem.loaded_specs.map{|n,s| [n,s.version.to_s]}.to_h
23
- end
5
+ class Dependencies
6
+ def initialize config, verbose: false, &block
7
+ @config = config
8
+ @verbose = verbose
24
9
 
25
- Bundler.unload!
10
+ instance_eval &block
26
11
 
27
- Bundler.ui = verbose ? Bundler::UI::Shell.new : nil
28
- MyPKI.init if Bundler.settings['dependencies.mypki']
29
-
30
- warn 'Dependencies installing. This could take a minute ...'
31
- old_root = Bundler.method(:root)
32
-
33
- def Bundler.root
34
- Bundler::SharedHelpers.pwd.expand_path
12
+ gemfile do
13
+ # tell bundler to use our gem sources
14
+ Gem.sources.each {|source| source source.to_s}
15
+ instance_eval &block
35
16
  end
36
-
37
- ENV['BUNDLE_GEMFILE'] ||= 'Gemfile'
38
-
39
- builder = Dsl.new
40
- builder.instance_eval(&gemfile)
17
+ end
41
18
 
42
- Gem::ConfigFile.new ['sources']
43
- Gem.sources.each {|s| builder.source s}
19
+ def gem name, *args
20
+ send *@config[name] if @config[name]
21
+ end
44
22
 
45
- ACTIVE_GEMS.each do |name,version|
46
- builder.gem name, version, require: false
23
+ def exec string
24
+ stdout, stderr, exit_status = Open3.capture3(string)
25
+
26
+ if exit_status.success?
27
+ if @verbose
28
+ Bundler.ui.info stdout unless stdout.empty?
29
+ Bundler.ui.warn stderr unless stderr.empty?
30
+ end
31
+ else
32
+ puts stdout unless stdout.empty?
33
+ warn stderr unless stderr.empty?
34
+ raise "\"exec '#{string}'\" failed on dependency installation"
47
35
  end
36
+ end
48
37
 
49
- Config.process builder
50
- definition = builder.to_definition(nil, true)
51
-
52
- def definition.lock(*); end
53
- definition.validate_ruby!
54
-
55
- Bundler::Installer.install(Bundler.root, definition, :system => true)
56
-
57
- runtime = Bundler::Runtime.new(nil, definition)
58
- runtime.setup.require
59
-
60
- bundler_module = class << Bundler; self; end
61
- bundler_module.send(:define_method, :root, old_root)
38
+ # gemfiles allow specifying alternate sources for gems
39
+ # make sure we check the block for gems in those sources
40
+ def source &block
41
+ instance_eval &block if block_given?
42
+ end
62
43
 
63
- html = IRuby.html <<-HTML
64
- <div style='
65
- margin: -0.4em;
66
- padding: 0.4em;
67
- background: rgba(0, 255, 0, .3);
68
- font-family: monospace;
69
- '>
70
- Dependencies successfully installed.
44
+ def to_html
45
+ <<-HTML
46
+ <div style='background: rgba(0,255,0,0.3);
47
+ font-family: monospace;
48
+ padding: 5px;'>
49
+ <b>Dependencies successfully installed!</b>
71
50
  </div>
72
51
  HTML
73
-
74
- IRuby.display html; nil
75
52
  end
76
53
  end
77
54
  end
78
55
 
79
- def dependencies *args, &block
80
- IRuby::Dependencies.dependencies *args, &block
56
+ def dependencies **params, &block
57
+ config={}
58
+
59
+ begin
60
+ if config_path = Bundler.settings['dependencies.config']
61
+ uri = URI config_path
62
+
63
+ json = case uri.scheme
64
+ when /http/
65
+ Net::HTTP.get(uri)
66
+ else
67
+ File.read(uri.path)
68
+ end
69
+
70
+ config = JSON.parse(json)
71
+ end
72
+
73
+ rescue => ex
74
+ warn "iruby-dependencies could not load #{config_path}: #{ex.message}"
75
+ end
76
+
77
+ IRuby::Dependencies.new config, **params, &block
81
78
  end
@@ -1,5 +1,5 @@
1
1
  module IRuby
2
- module Dependencies
3
- VERSION = "2.0.4"
2
+ class Dependencies
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,72 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iruby-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle King
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-21 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: multi_json
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.12'
48
- type: :runtime
47
+ version: '0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.12'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
69
- description:
68
+ version: '0'
69
+ description:
70
70
  email:
71
71
  - kylejking@gmail.com
72
72
  executables: []
@@ -82,14 +82,12 @@ files:
82
82
  - bin/setup
83
83
  - iruby-dependencies.gemspec
84
84
  - lib/iruby/dependencies.rb
85
- - lib/iruby/dependencies/config.rb
86
- - lib/iruby/dependencies/dsl.rb
87
- - lib/iruby/dependencies/unload.rb
88
85
  - lib/iruby/dependencies/version.rb
89
86
  homepage: https://github.com/jupyter-gallery/iruby-dependencies
90
- licenses: []
87
+ licenses:
88
+ - MIT
91
89
  metadata: {}
92
- post_install_message:
90
+ post_install_message:
93
91
  rdoc_options: []
94
92
  require_paths:
95
93
  - lib
@@ -104,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
102
  - !ruby/object:Gem::Version
105
103
  version: '0'
106
104
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.6.4
109
- signing_key:
105
+ rubygems_version: 3.1.4
106
+ signing_key:
110
107
  specification_version: 4
111
108
  summary: IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter
112
109
  Notebooks
@@ -1,46 +0,0 @@
1
- require 'net/https'
2
- require 'multi_json'
3
-
4
- module IRuby
5
- module Dependencies
6
- class Config
7
- def self.process builder
8
- if url = Bundler.settings['dependencies.config']
9
- begin
10
- uri = URI Bundler.settings['dependencies.config']
11
- config = MultiJson.load(Net::HTTP.get(uri))
12
- rescue => ex
13
- warn "Could not fetch remote IRuby::Dependencies config from #{url}: #{ex.message}"
14
- else
15
- loop do
16
- gem_added = false
17
-
18
- if commands = config.delete('*')
19
- commands.each do |command|
20
- method, *args = command
21
- builder.send method, *args
22
- gem_added ||= method == 'gem'
23
- end
24
- end
25
-
26
- definition = builder.to_definition nil, true
27
- #definition.resolve
28
-
29
- definition.specs.each do |spec|
30
- if commands = config.delete(spec.name)
31
- commands.each do |command|
32
- method, *args = command
33
- builder.send method, *args
34
- gem_added ||= method == 'gem'
35
- end
36
- end
37
- end
38
-
39
- break unless gem_added
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,96 +0,0 @@
1
- require 'open3'
2
-
3
- module IRuby
4
- module Dependencies
5
- class Dsl < ::Bundler::Dsl
6
- def config hash
7
- hash.each do |key,value|
8
- Bundler.settings[key] = value
9
- end
10
- end
11
-
12
- def exec string
13
- stdout, stderr, exit_status = Open3.capture3(string)
14
-
15
- if exit_status.success?
16
- Bundler.ui.info stdout unless stdout.empty?
17
- Bundler.ui.warn stderr unless stderr.empty?
18
- else
19
- puts stdout unless stdout.empty?
20
- warn stderr unless stderr.empty?
21
- raise "\"exec '#{string}'\" failed on dependency installation"
22
- end
23
- end
24
-
25
- def eval string
26
- super string
27
- end
28
-
29
- def css *paths
30
- paths.each do |path|
31
- url = full_url path
32
- html = "<link rel='stylesheet' href='#{url}'>"
33
- IRuby.display IRuby.html(html)
34
- end
35
- end
36
-
37
- def define hash
38
- mapped = hash.map do |mod,path|
39
- [mod, full_url(path)]
40
- end.to_h
41
-
42
- js = <<-JS
43
- requirejs.config({
44
- map: {
45
- '*': #{MultiJson.dump(mapped)}
46
- }
47
- });
48
- JS
49
-
50
- IRuby.display IRuby.javascript(js)
51
- end
52
-
53
- def script *paths
54
- paths.each do |path|
55
- url = full_url path
56
- html = "<script src='#{url}'></script>"
57
- IRuby.display IRuby.html(html)
58
- end
59
- end
60
-
61
- def url url
62
- @url = url
63
- end
64
-
65
- def gem name, *args
66
- if version = ACTIVE_GEMS[name]
67
- options = args.last.is_a?(Hash) ? args.pop.dup : {}
68
-
69
- unless args.empty? or args == [version]
70
- raise GemfileError, "The IRuby runtime has already loaded #{name}-#{version}. If you need a different version, you'll need to install it manually and restart IRuby."
71
- else
72
- super name, [version], options
73
- end
74
- else
75
- super name, *args
76
- end
77
- end
78
-
79
- private
80
-
81
- def full_url path
82
- if path[/^https?:/]
83
- path
84
- else
85
- if @url
86
- File.join @url, path
87
- elsif url = Bundler.settings['dependencies.url']
88
- File.join url, path
89
- else
90
- raise "Cannot inject #{path} without a base url"
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,19 +0,0 @@
1
- require 'bundler'
2
-
3
- # a minor modification of the code from the
4
- # bundler-unload gem
5
- module Bundler
6
- ORIGINAL_SPECS = []
7
-
8
- class << self
9
- def unload!
10
- if ORIGINAL_SPECS.empty?
11
- ORIGINAL_SPECS.concat Gem::Specification._all
12
- end
13
-
14
- @load = @definition = nil
15
- ENV.replace ORIGINAL_ENV
16
- Gem::Specification.all = ORIGINAL_SPECS
17
- end
18
- end
19
- end