iruby-dependencies 2.0.6 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 343e8e2a6cee1ca5460673c2de128f5d8fc4c747
4
- data.tar.gz: 76cbca0dec91725bd6ac263a71631b0503d4f4f4
2
+ SHA256:
3
+ metadata.gz: 2b29975404014c378d839ad8041853c824037dfd9df1eb3d156e68c3572d7405
4
+ data.tar.gz: 8a88cd8563a1e709f7a3e471650552aafdcbb1b80d29c6be9d3ea8218f8cc497
5
5
  SHA512:
6
- metadata.gz: d933f9c488518a2ebfa9599507bb11dd066a50003a57dc571671e27d508205a6294c6245754b67f8b40ae6f37870a065429781b6d4f697dd5f5e989baded7008
7
- data.tar.gz: 96f8cdbbcc37c6e44d71cc4d092010909e1116f4d868632fdbcc5b663bddc397946041927e7885784a320f219ca9c7bf7213f1dad1fd0161023a053acbc0ab52
6
+ metadata.gz: b189de7338a4d576ee7425b5573d8e665fda57a14b9aac3ea23954b0342d36f6ebcfba14096b2240d15c12fa5925c720799f4f6762cb752d4052e0c1ec37d260
7
+ data.tar.gz: 3d52f2414e53c5baad1c435d4814e679b6f4d69c5876e28384d0e3bc971bd5f1ab086cb1b1a9822dfbaa76a56fe45a6af940d1b063672e97cdf7e71c24ebba5d
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,83 +1,79 @@
1
- require 'bundler'
2
- require 'iruby/dependencies/dsl'
3
- require 'iruby/dependencies/config'
4
- require 'iruby/dependencies/unload'
5
- require 'iruby/dependencies/shared_helpers'
6
- require 'iruby/dependencies/version'
7
-
8
- # require 'mypki' if requested so it is an active gem
9
- if Bundler.settings['dependencies.mypki']
10
- require 'mypki'
11
- require 'erector'
12
- end
1
+ require 'json'
2
+ require 'net/https'
3
+ require 'bundler/inline'
13
4
 
14
5
  module IRuby
15
- module Dependencies
16
- ACTIVE_GEMS = {}
17
-
18
- # activate default gems
19
- %w[bigdecimal io-console json psych rdoc].each {|g| gem g}
20
-
21
- # this code is taken from bundler/inline with small changes
22
- def self.dependencies verbose: false, &gemfile
23
- if ACTIVE_GEMS.empty?
24
- ACTIVE_GEMS.merge! Gem.loaded_specs.map{|n,s| [n,s.version.to_s]}.to_h
25
- end
6
+ class Dependencies
7
+ def initialize config, verbose: false, &block
8
+ @config = config
9
+ @verbose = verbose
26
10
 
27
- Bundler.unload!
11
+ instance_eval &block
28
12
 
29
- Bundler.ui = verbose ? Bundler::UI::Shell.new : nil
30
- MyPKI.init if Bundler.settings['dependencies.mypki']
31
-
32
- warn 'Dependencies installing. This could take a minute ...'
33
- old_root = Bundler.method(:root)
34
-
35
- def Bundler.root
36
- Bundler::SharedHelpers.pwd.expand_path
13
+ gemfile do
14
+ # tell bundler to use our gem sources
15
+ Gem.sources.each {|source| source source.to_s}
16
+ instance_eval &block
37
17
  end
38
-
39
- ENV['BUNDLE_GEMFILE'] ||= 'Gemfile'
40
-
41
- builder = Dsl.new
42
- builder.instance_eval(&gemfile)
18
+ end
43
19
 
44
- Gem::ConfigFile.new ['sources']
45
- Gem.sources.each {|s| builder.source s}
20
+ def gem name, *args
21
+ send *@config[name] if @config[name]
22
+ end
46
23
 
47
- ACTIVE_GEMS.each do |name,version|
48
- builder.gem name, version, require: false
24
+ def exec string
25
+ stdout, stderr, exit_status = Open3.capture3(string)
26
+
27
+ if exit_status.success?
28
+ if @verbose
29
+ Bundler.ui.info stdout unless stdout.empty?
30
+ Bundler.ui.warn stderr unless stderr.empty?
31
+ end
32
+ else
33
+ puts stdout unless stdout.empty?
34
+ warn stderr unless stderr.empty?
35
+ raise "\"exec '#{string}'\" failed on dependency installation"
49
36
  end
37
+ end
50
38
 
51
- Config.process builder
52
- definition = builder.to_definition(nil, true)
53
-
54
- def definition.lock(*); end
55
- definition.validate_ruby!
56
-
57
- Bundler::Installer.install(Bundler.root, definition, :system => true)
58
-
59
- runtime = Bundler::Runtime.new(nil, definition)
60
- runtime.setup.require
61
-
62
- bundler_module = class << Bundler; self; end
63
- bundler_module.send(:define_method, :root, old_root)
39
+ # gemfiles allow specifying alternate sources for gems
40
+ # make sure we check the block for gems in those sources
41
+ def source *args, &block
42
+ instance_eval &block if block_given?
43
+ end
64
44
 
65
- html = IRuby.html <<-HTML
66
- <div style='
67
- margin: -0.4em;
68
- padding: 0.4em;
69
- background: rgba(0, 255, 0, .3);
70
- font-family: monospace;
71
- '>
72
- Dependencies successfully installed.
45
+ def to_html
46
+ <<-HTML
47
+ <div style='background: rgba(0,255,0,0.3);
48
+ font-family: monospace;
49
+ padding: 5px;'>
50
+ <b>Dependencies successfully installed!</b>
73
51
  </div>
74
52
  HTML
75
-
76
- IRuby.display html; nil
77
53
  end
78
54
  end
79
55
  end
80
56
 
81
- def dependencies *args, &block
82
- IRuby::Dependencies.dependencies *args, &block
57
+ def dependencies **params, &block
58
+ config={}
59
+
60
+ begin
61
+ if config_path = Bundler.settings['dependencies.config']
62
+ uri = URI config_path
63
+
64
+ json = case uri.scheme
65
+ when /http/
66
+ Net::HTTP.get(uri)
67
+ else
68
+ File.read(uri.path)
69
+ end
70
+
71
+ config = JSON.parse(json)
72
+ end
73
+
74
+ rescue => ex
75
+ warn "iruby-dependencies could not load #{config_path}: #{ex.message}"
76
+ end
77
+
78
+ IRuby::Dependencies.new config, **params, &block
83
79
  end
@@ -1,5 +1,5 @@
1
1
  module IRuby
2
- module Dependencies
3
- VERSION = "2.0.6"
2
+ class Dependencies
3
+ VERSION = "3.0.2"
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.6
4
+ version: 3.0.2
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-08-12 00:00:00.000000000 Z
11
+ date: 2021-01-12 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,15 +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/shared_helpers.rb
88
- - lib/iruby/dependencies/unload.rb
89
85
  - lib/iruby/dependencies/version.rb
90
86
  homepage: https://github.com/jupyter-gallery/iruby-dependencies
91
- licenses: []
87
+ licenses:
88
+ - MIT
92
89
  metadata: {}
93
- post_install_message:
90
+ post_install_message:
94
91
  rdoc_options: []
95
92
  require_paths:
96
93
  - lib
@@ -105,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
102
  - !ruby/object:Gem::Version
106
103
  version: '0'
107
104
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.5.1
110
- signing_key:
105
+ rubygems_version: 3.1.4
106
+ signing_key:
111
107
  specification_version: 4
112
108
  summary: IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter
113
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_remotely!
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,7 +0,0 @@
1
- module Bundler
2
- # https://github.com/bundler/bundler/issues/4837
3
- module SharedHelpers
4
- def clean_load_path
5
- end
6
- end
7
- end
@@ -1,17 +0,0 @@
1
- # a minor modification of the code from the
2
- # bundler-unload gem
3
- module Bundler
4
- ORIGINAL_SPECS = []
5
-
6
- class << self
7
- def unload!
8
- if ORIGINAL_SPECS.empty?
9
- ORIGINAL_SPECS.concat Gem::Specification._all
10
- end
11
-
12
- @load = @definition = nil
13
- ENV.replace ORIGINAL_ENV
14
- Gem::Specification.all = ORIGINAL_SPECS
15
- end
16
- end
17
- end