iruby-dependencies 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +7 -28
- data/iruby-dependencies.gemspec +4 -4
- data/lib/iruby/dependencies.rb +61 -65
- data/lib/iruby/dependencies/version.rb +2 -2
- metadata +22 -26
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93eac5474a61ffd224821a9423743f211683c362693002c0ae970fbab4e0df0a
|
4
|
+
data.tar.gz: 0375f511e0d79f2e52fa5e678d22a9e85b8c1e695ffa4a5d8db730ccdb43804a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
@@ -25,15 +21,13 @@ 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
|
-
| `dependencies.mypki` | Use MyPKI to pull from a PKI-enabled gem server |
|
34
|
-
| `dependencies.config` | The URL to pull a remote iruby-dependencies config as JSON.|
|
26
|
+
```bash
|
27
|
+
$ bundle config dependencies.config /home/jovyan/dependencies.config
|
28
|
+
```
|
35
29
|
|
36
|
-
|
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:
|
37
31
|
|
38
32
|
```json
|
39
33
|
{
|
@@ -43,19 +37,8 @@ Remote configurations are generally used to install gem dependencies. For exampl
|
|
43
37
|
}
|
44
38
|
```
|
45
39
|
|
46
|
-
This configuration will install the `gsl` yum package if the user uses `IRuby::Dependencies` to install the `gsl` gem.
|
47
|
-
|
48
40
|
## Usage
|
49
41
|
|
50
|
-
`IRuby::Dependencies` uses the [Bundler Gemfile syntax](http://bundler.io/v1.5/gemfile.html) with some additional methods:
|
51
|
-
|
52
|
-
| Method | Description |
|
53
|
-
| ------ | ----------- |
|
54
|
-
| `script <url>` | Loads the javascript at the given url into the notebook as a `script` tag |
|
55
|
-
| `define <hash>` | Defines alternate paths for requirejs modules. Keys are modules, values are paths |
|
56
|
-
| `exec <string>` | Executes the system command, for example `yum install gsl` |
|
57
|
-
| `css <string>` | Loads the stylesheet at the given url into the notebook as a `link` tag
|
58
|
-
|
59
42
|
To see the normal bundler output, pass `verbose: true` to the dependencies method:
|
60
43
|
|
61
44
|
```
|
@@ -63,8 +46,4 @@ dependencies verbose: true do
|
|
63
46
|
gem 'http'
|
64
47
|
gem 'addressable'
|
65
48
|
end
|
66
|
-
```
|
67
|
-
|
68
|
-
## Active Gems
|
69
|
-
|
70
|
-
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
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "iruby", "~> 0.
|
22
|
-
spec.add_dependency "
|
23
|
-
spec.add_dependency "bundler", "~> 1.16"
|
21
|
+
spec.add_dependency "iruby", "~> 0.4"
|
22
|
+
spec.add_dependency "bundler", "~> 2"
|
24
23
|
|
25
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "rake"
|
26
26
|
end
|
data/lib/iruby/dependencies.rb
CHANGED
@@ -1,82 +1,78 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
# require 'mypki' if requested so it is an active gem
|
4
|
-
if Bundler.settings['dependencies.mypki']
|
5
|
-
require 'mypki'
|
6
|
-
require 'erector'
|
7
|
-
end
|
8
|
-
|
9
|
-
if gems = Bundler.settings['dependencies.require']
|
10
|
-
gems.split(':').each {|gem| require gem}
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'iruby/dependencies/dsl'
|
14
|
-
require 'iruby/dependencies/config'
|
15
|
-
require 'iruby/dependencies/shared_helpers'
|
16
|
-
require 'iruby/dependencies/version'
|
1
|
+
require 'net/https'
|
2
|
+
require 'bundler/inline'
|
17
3
|
|
18
4
|
module IRuby
|
19
|
-
|
20
|
-
|
5
|
+
class Dependencies
|
6
|
+
def initialize config, verbose: false, &block
|
7
|
+
@config = config
|
8
|
+
@verbose = verbose
|
21
9
|
|
22
|
-
|
23
|
-
def self.dependencies verbose: false, &gemfile
|
24
|
-
if ACTIVE_GEMS.empty?
|
25
|
-
ACTIVE_GEMS.merge! Gem.loaded_specs.map{|n,s| [n,s.version.to_s]}.to_h
|
26
|
-
end
|
10
|
+
instance_eval &block
|
27
11
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
old_root = Bundler.method(:root)
|
33
|
-
|
34
|
-
def Bundler.root
|
35
|
-
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
|
36
16
|
end
|
37
|
-
|
38
|
-
ENV['BUNDLE_GEMFILE'] ||= 'Gemfile'
|
39
|
-
|
40
|
-
builder = Dsl.new
|
41
|
-
builder.instance_eval(&gemfile)
|
17
|
+
end
|
42
18
|
|
43
|
-
|
44
|
-
|
19
|
+
def gem name, *args
|
20
|
+
send *@config[name] if @config[name]
|
21
|
+
end
|
45
22
|
|
46
|
-
|
47
|
-
|
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"
|
48
35
|
end
|
36
|
+
end
|
49
37
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Bundler::Installer.install(Bundler.root, definition, :system => true)
|
57
|
-
|
58
|
-
runtime = Bundler::Runtime.new(nil, definition)
|
59
|
-
runtime.setup.require
|
60
|
-
|
61
|
-
bundler_module = class << Bundler; self; end
|
62
|
-
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
|
63
43
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'>
|
71
|
-
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>
|
72
50
|
</div>
|
73
51
|
HTML
|
74
|
-
|
75
|
-
IRuby.display html; nil
|
76
52
|
end
|
77
53
|
end
|
78
54
|
end
|
79
55
|
|
80
|
-
def dependencies
|
81
|
-
|
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
|
82
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iruby-dependencies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
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:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iruby
|
@@ -16,57 +16,57 @@ dependencies:
|
|
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
85
|
- lib/iruby/dependencies/version.rb
|
89
86
|
homepage: https://github.com/jupyter-gallery/iruby-dependencies
|
90
87
|
licenses:
|
91
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
|