iruby-dependencies 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d776a0bfc545dece58b742386bcee7eecb9c4069
4
+ data.tar.gz: e71834db955a0085aafa2380abde5b25602294f3
5
+ SHA512:
6
+ metadata.gz: e8a0c38a50b91bb020a58987cc117756bcf18381045e0d646456a27fe07a6f24beea8f5899e0d350ea58fb4e12bfc175bbff39dd20dd36ccb275307d98fa4cd0
7
+ data.tar.gz: 0be6783def0c53f6cf176225f14af3f9cec3de9371f8a5914e2ef2c93598014dccfa5aed2f2da6bba25e330178e3878567b3bee9fecc33e9596a78b43e6ccd7c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iruby-dependencies.gemspec
4
+ gemspec
5
+
6
+ gem 'pry', group: 'development'
7
+ gem 'ffi-rzmq', group: 'development'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # IRuby::Dependencies
2
+
3
+ IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter Notebooks. For example,
4
+
5
+ ```ruby
6
+ require 'iruby/dependencies'
7
+
8
+ dependencies do
9
+ gem 'http'
10
+ gem 'addressable'
11
+ end
12
+ ```
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ $ gem install iruby-dependencies
18
+ ```
19
+
20
+ You'll have to restart any IRuby kernels already running.
21
+
22
+ ## Usage
23
+
24
+ IRuby::Dependencies uses the [Bundler Gemfile syntax](http://bundler.io/v1.5/gemfile.html) with some additional methods:
25
+
26
+ | Method | Description |
27
+ | ------ | ----------- |
28
+ | `script <url>` | Loads the javascript at the given url into the notebook as a `script` tag |
29
+ | `define <hash>` | Defines alternate paths for requirejs modules. Keys are modules, values are paths |
30
+ | `exec <string>` | Executes the system command, for example `yum install gsl` |
31
+ | `css` | Loads the stylesheet at the given url into the notebook as a `link` tag
32
+
33
+ To see the normal bundler output, pass `verbose: true` to the dependencies method:
34
+
35
+ ```
36
+ dependencies verbose: true do
37
+ gem 'http'
38
+ gem 'addressable'
39
+ end
40
+ ```
41
+
42
+ ## Active Gems
43
+
44
+ Gems active at the time IRuby::Dependencies are added to the dependency bundle. This means that you cannot specify a different version of a gem already being used by IRuby. If you really need a different version of that gem, install it on the command line and restart the kernel.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "iruby/dependencies"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iruby/dependencies/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iruby-dependencies"
8
+ spec.version = IRuby::Dependencies::VERSION
9
+ spec.authors = ["Kyle King"]
10
+ spec.email = ["kylejking@gmail.com"]
11
+
12
+ spec.summary = %q{IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter Notebooks}
13
+ spec.homepage = "https://github.com/kylekyle/iruby-dependencies"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
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"
24
+ end
@@ -0,0 +1,77 @@
1
+ require 'bundler'
2
+ require 'iruby/dependencies/dsl'
3
+ require 'iruby/dependencies/config'
4
+ require 'iruby/dependencies/version'
5
+
6
+ module IRuby
7
+ module Dependencies
8
+ paths = Gem.path.map {|p| File.join p, 'gems'}
9
+
10
+ ACTIVE_GEMS = $LOAD_PATH.each_with_object({}) do |path,hash|
11
+ paths.each do |gem_path|
12
+ match = path.match /#{gem_path}\/((?:\w|-)+)-((?:\d+\.?)+)/
13
+ hash.merge! Hash[*match.captures] unless match.nil?
14
+ end
15
+ end
16
+
17
+ # this code is taken from bundler/inline with small changes
18
+ def self.dependencies verbose: false, &gemfile
19
+ warn 'Dependencies installing. This could take a minute ...'
20
+
21
+ Bundler.ui = verbose ? Bundler::UI::Shell.new : nil
22
+
23
+ if Bundler.settings['dependencies.mypki']
24
+ require 'mypki'
25
+ MyPKI.init
26
+ end
27
+
28
+ old_root = Bundler.method(:root)
29
+
30
+ def Bundler.root
31
+ Bundler::SharedHelpers.pwd.expand_path
32
+ end
33
+
34
+ ENV['BUNDLE_GEMFILE'] ||= 'Gemfile'
35
+
36
+ builder = Dsl.new
37
+ builder.instance_eval(&gemfile)
38
+
39
+ Gem.sources.each {|s| builder.source s}
40
+
41
+ ACTIVE_GEMS.each do |name,version|
42
+ builder.gem name, version
43
+ end
44
+
45
+ Config.process builder
46
+ definition = builder.to_definition(nil, true)
47
+
48
+ def definition.lock(*); end
49
+ definition.validate_ruby!
50
+
51
+ Bundler::Installer.install(Bundler.root, definition, :system => true)
52
+
53
+ runtime = Bundler::Runtime.new(nil, definition)
54
+ runtime.setup.require
55
+
56
+ bundler_module = class << Bundler; self; end
57
+ bundler_module.send(:define_method, :root, old_root)
58
+
59
+ html = IRuby.html <<-HTML
60
+ <div style='
61
+ margin: -0.4em;
62
+ padding: 0.4em;
63
+ background: rgba(0, 255, 0, .3);
64
+ font-family: monospace;
65
+ '>
66
+ Dependencies successfully installed.
67
+ </div>
68
+ HTML
69
+
70
+ IRuby.display html; nil
71
+ end
72
+ end
73
+ end
74
+
75
+ def dependencies *args, &block
76
+ IRuby::Dependencies.dependencies *args, &block
77
+ end
@@ -0,0 +1,45 @@
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
+
28
+ definition.specs.each do |spec|
29
+ if commands = config.delete(spec.name)
30
+ commands.each do |command|
31
+ method, *args = command
32
+ builder.send method, *args
33
+ gem_added ||= method == 'gem'
34
+ end
35
+ end
36
+ end
37
+
38
+ break unless gem_added
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,96 @@
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
@@ -0,0 +1,5 @@
1
+ module IRuby
2
+ module Dependencies
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iruby-dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle King
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: iruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - kylejking@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - iruby-dependencies.gemspec
84
+ - lib/iruby/dependencies.rb
85
+ - lib/iruby/dependencies/config.rb
86
+ - lib/iruby/dependencies/dsl.rb
87
+ - lib/iruby/dependencies/version.rb
88
+ homepage: https://github.com/kylekyle/iruby-dependencies
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: IRuby::Dependencies is a module for injecting Ruby dependencies into Jupyter
111
+ Notebooks
112
+ test_files: []