iruby-dependencies 2.0.7 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +19 -18
- data/iruby-dependencies.gemspec +6 -4
- data/lib/iruby/dependencies.rb +63 -65
- data/lib/iruby/dependencies/version.rb +2 -2
- metadata +28 -32
- data/lib/iruby/dependencies/config.rb +0 -46
- data/lib/iruby/dependencies/dsl.rb +0 -96
- data/lib/iruby/dependencies/shared_helpers.rb +0 -7
- data/lib/iruby/dependencies/unload.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a9f26be7f6cea9980ff02687f9b7789d4641e71559f0a32bfb073a390541995
|
4
|
+
data.tar.gz: e404c4c83e29c18d4064950008e8e5ad613abf28a6da7d597b14f6fc9525e287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd98b0216baa2ee3dfca076713ae2baefd3006a18f5005352c9da7794750a3a7c329d27b9d9ee819f518fa20451b5d286a4da6b4779e56dde94e0ff3b1a93ea
|
7
|
+
data.tar.gz: 56db227e28205cf522b589d2b3cf5455616c6ba1468ca0711764840ed81b234df5e9d531e4fa2ea09d270c5f8b451864ffd9406d93ab888067a82b243cf0606c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRuby::Dependencies
|
2
2
|
|
3
|
-
`IRuby::Dependencies` is a
|
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
|
-
##
|
22
|
+
## Configuration
|
27
23
|
|
28
|
-
`IRuby::Dependencies`
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
+
```
|
data/iruby-dependencies.gemspec
CHANGED
@@ -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 "
|
22
|
-
|
23
|
-
spec.add_development_dependency "
|
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
|
data/lib/iruby/dependencies.rb
CHANGED
@@ -1,83 +1,81 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
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
|
-
|
16
|
-
|
6
|
+
class Dependencies
|
7
|
+
def initialize config, verbose: false, &block
|
8
|
+
@config = config
|
9
|
+
@verbose = verbose
|
17
10
|
|
18
|
-
|
19
|
-
%w[bigdecimal io-console json psych rdoc].each {|g| gem g}
|
11
|
+
instance_eval &block
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
gemfile do
|
14
|
+
# tell bundler to use our gem sources
|
15
|
+
Gem.sources.each {|source| source source.to_s}
|
16
|
+
instance_eval &block
|
25
17
|
end
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
20
|
+
def gem name, *args
|
21
|
+
if commands = @config[name]
|
22
|
+
commands.each {|command| send *command}
|
37
23
|
end
|
38
|
-
|
39
|
-
ENV['BUNDLE_GEMFILE'] ||= 'Gemfile'
|
40
|
-
|
41
|
-
builder = Dsl.new
|
42
|
-
builder.instance_eval(&gemfile)
|
43
|
-
|
44
|
-
Gem::ConfigFile.new ['sources']
|
45
|
-
Gem.sources.each {|s| builder.source s}
|
24
|
+
end
|
46
25
|
|
47
|
-
|
48
|
-
|
26
|
+
def exec string
|
27
|
+
stdout, stderr, exit_status = Open3.capture3(string)
|
28
|
+
|
29
|
+
if exit_status.success?
|
30
|
+
if @verbose
|
31
|
+
Bundler.ui.info stdout unless stdout.empty?
|
32
|
+
Bundler.ui.warn stderr unless stderr.empty?
|
33
|
+
end
|
34
|
+
else
|
35
|
+
puts stdout unless stdout.empty?
|
36
|
+
warn stderr unless stderr.empty?
|
37
|
+
raise "\"exec '#{string}'\" failed on dependency installation"
|
49
38
|
end
|
39
|
+
end
|
50
40
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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)
|
41
|
+
# gemfiles allow specifying alternate sources for gems
|
42
|
+
# make sure we check the block for gems in those sources
|
43
|
+
def source *args, &block
|
44
|
+
instance_eval &block if block_given?
|
45
|
+
end
|
64
46
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
'>
|
72
|
-
Dependencies successfully installed.
|
47
|
+
def to_html
|
48
|
+
<<-HTML
|
49
|
+
<div style='background: rgba(0,255,0,0.3);
|
50
|
+
font-family: monospace;
|
51
|
+
padding: 5px;'>
|
52
|
+
<b>Dependencies successfully installed!</b>
|
73
53
|
</div>
|
74
54
|
HTML
|
75
|
-
|
76
|
-
IRuby.display html; nil
|
77
55
|
end
|
78
56
|
end
|
79
57
|
end
|
80
58
|
|
81
|
-
def dependencies
|
82
|
-
|
59
|
+
def dependencies **params, &block
|
60
|
+
config={}
|
61
|
+
|
62
|
+
begin
|
63
|
+
if config_path = Bundler.settings['dependencies.config']
|
64
|
+
uri = URI config_path
|
65
|
+
|
66
|
+
json = case uri.scheme
|
67
|
+
when /http/
|
68
|
+
Net::HTTP.get(uri)
|
69
|
+
else
|
70
|
+
File.read(uri.path)
|
71
|
+
end
|
72
|
+
|
73
|
+
config = JSON.parse(json)
|
74
|
+
end
|
75
|
+
|
76
|
+
rescue => ex
|
77
|
+
warn "iruby-dependencies could not load #{config_path}: #{ex.message}"
|
78
|
+
end
|
79
|
+
|
80
|
+
IRuby::Dependencies.new config, **params, &block
|
83
81
|
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:
|
4
|
+
version: 3.0.3
|
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:
|
11
|
+
date: 2021-03-02 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:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
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:
|
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: '
|
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: '
|
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
|
-
|
109
|
-
|
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,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
|