bindeps 1.0.1 → 1.1.0

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
2
  SHA1:
3
- metadata.gz: 7ce60e8a556a5d2d0ca0d4e562c72ed1139d5c23
4
- data.tar.gz: 4a6aa254fbf74d7b2ac4d725c5f05fe431d418eb
3
+ metadata.gz: 6b3ffdc990f2ecff30e081c0a569c8a940a77479
4
+ data.tar.gz: 041feed4e988c6b939ae895b3628ea6db5893018
5
5
  SHA512:
6
- metadata.gz: 7dcbc0dafccf0c71371fcd886a3832d9910831d5660a94c4917ad818792f97ca772dc3c95d6409dbb1d629e32ed50470ce3f8e54508a9e7e8f6452fca10779c2
7
- data.tar.gz: a0c9e3988109d6c359289f267f5eb7f2f4e312ec6112dfbb58c8df61c97d3e882d2ca3b65e36080b6fbaaa56d131d89b96fea437e5bc12268696d05c6267a5d8
6
+ metadata.gz: b1ff2005808a9af7e46a22c46b01a87e6aed112ccf26b3516748f5a56f746543f0a0b6af73448d4e5d689c9c6b62539c10bef9ba3d2778db1658bca7b4c2ec2d
7
+ data.tar.gz: 5de0ad5c19d453e8a3a2614440f15a6e196d4115b4f3e90684200618ef9d825745f89d7a18fa7ee94ea241390e9fcd6ffc34f29235d055639722860909890ff8
@@ -3,6 +3,7 @@ require "unpacker"
3
3
  require "fixwhich"
4
4
  require "tmpdir"
5
5
  require "yaml"
6
+ require "fileutils"
6
7
 
7
8
  module Bindeps
8
9
 
@@ -13,16 +14,19 @@ module Bindeps
13
14
  if dependencies.is_a? String
14
15
  dependencies = YAML.load_file dependencies
15
16
  end
16
- tmpdir = Dir.mktmpdir
17
- Dir.chdir(tmpdir) do
18
- dependencies.each_pair do |name, config|
19
- unpack = config.key?('unpack') ? config['unpack'] : true;
20
- d = Dependency.new(name,
21
- config['binaries'],
22
- config['version'],
23
- config['url'],
24
- unpack)
25
- d.install_missing
17
+ Dir.mktmpdir do |tmpdir|
18
+ Dir.chdir(tmpdir) do
19
+ dependencies.each_pair do |name, config|
20
+ unpack = config.key?('unpack') ? config['unpack'] : true;
21
+ libraries = config.key?('libraries') ? config['libraries'] : []
22
+ d = Dependency.new(name,
23
+ config['binaries'],
24
+ config['version'],
25
+ config['url'],
26
+ unpack,
27
+ libraries)
28
+ d.install_missing
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -33,17 +37,20 @@ module Bindeps
33
37
  if dependencies.is_a? String
34
38
  dependencies = YAML.load_file dependencies
35
39
  end
36
- tmpdir = Dir.mktmpdir
37
40
  missing = []
38
- Dir.chdir(tmpdir) do
39
- dependencies.each_pair do |name, config|
40
- unpack = config.key?('unpack') ? config['unpack'] : true;
41
- d = Dependency.new(name,
42
- config['binaries'],
43
- config['version'],
44
- config['url'],
45
- unpack)
46
- missing << d unless d.all_installed?
41
+ Dir.mktmpdir do |tmpdir|
42
+ Dir.chdir(tmpdir) do
43
+ dependencies.each_pair do |name, config|
44
+ unpack = config.key?('unpack') ? config['unpack'] : true;
45
+ libraries = config.key?('libraries') ? config['libraries'] : []
46
+ d = Dependency.new(name,
47
+ config['binaries'],
48
+ config['version'],
49
+ config['url'],
50
+ unpack,
51
+ libraries)
52
+ missing << d unless d.all_installed?
53
+ end
47
54
  end
48
55
  end
49
56
  missing
@@ -51,17 +58,19 @@ module Bindeps
51
58
 
52
59
  class Dependency
53
60
 
54
- attr_reader :name, :version, :binaries
61
+ attr_reader :name, :version, :binaries, :libraries
55
62
 
56
63
  include Which
57
64
 
58
- def initialize(name, binaries, versionconfig, urlconfig, unpack)
65
+ def initialize(name, binaries, versionconfig, urlconfig,
66
+ unpack, libraries=[])
59
67
  @name = name
60
68
  unless binaries.is_a? Array
61
69
  raise ArgumentError,
62
70
  "binaries must be an array"
63
71
  end
64
72
  @binaries = binaries
73
+ @libraries = libraries
65
74
  @version = versionconfig['number']
66
75
  @version_cmd = versionconfig['command']
67
76
  @url = choose_url urlconfig
@@ -70,7 +79,7 @@ module Bindeps
70
79
 
71
80
  def install_missing
72
81
  unless all_installed?
73
- puts "Installing #{@name}..."
82
+ puts "Installing #{@name} (#{@version})..."
74
83
  download
75
84
  unpack
76
85
  end
@@ -85,11 +94,13 @@ module Bindeps
85
94
  return sys[os]
86
95
  else
87
96
  raise UnsupportedSystemError,
88
- "bindeps config for #{@name} #{arch} doesn't contain an entry for #{os}"
97
+ "bindeps config for #{@name} #{arch} doesn't " +
98
+ "contain an entry for #{os}"
89
99
  end
90
100
  else
91
101
  raise UnsupportedSystemError,
92
- "bindeps config for #{@name} doesn't contain an entry for #{arch}"
102
+ "bindeps config for #{@name} doesn't contain an " +
103
+ "entry for #{arch}"
93
104
  end
94
105
  end
95
106
 
@@ -120,14 +131,16 @@ module Bindeps
120
131
  Unpacker.unpack(archive) do |dir|
121
132
  Dir.chdir dir do
122
133
  Dir['**/*'].each do |extracted|
123
- if @binaries.include? File.basename(extracted)
124
- install(extracted) unless File.directory?(extracted)
134
+ file = File.basename(extracted)
135
+ if @binaries.include?(file) || @libraries.include?(file)
136
+ dir = File.dirname extracted
137
+ install(extracted, dir) unless File.directory?(extracted)
125
138
  end
126
139
  end
127
140
  end
128
141
  end
129
142
  else
130
- install(@binaries.first)
143
+ install(@binaries.first, 'bin')
131
144
  end
132
145
  end
133
146
 
@@ -142,19 +155,37 @@ module Bindeps
142
155
 
143
156
  def installed? bin
144
157
  path = which(bin)
145
- if path
158
+ if path.length > 0
146
159
  ret = `#{@version_cmd} 2>&1`.split("\n").map{ |l| l.strip }.join('|')
147
160
  if ret && (/#{@version}/ =~ ret)
148
161
  return path
149
162
  end
163
+ else
164
+ if Dir.exist?("#{ENV['HOME']}/.local/bin")
165
+ ENV['PATH'] = ENV['PATH'] + ":#{ENV['HOME']}/.local/bin"
166
+ path = which(bin)
167
+ if path.length > 0
168
+ return path
169
+ end
170
+ end
150
171
  end
151
172
  false
152
173
  end
153
174
 
154
- def install bin
155
- bindir = File.join(ENV['GEM_HOME'], 'bin')
156
- install_location = File.join(bindir, File.basename(bin))
157
- FileUtils.install(bin, install_location, :mode => 0775)
175
+ def install(src, destprefix)
176
+ gem_home = ENV['GEM_HOME']
177
+ home = ENV['HOME']
178
+ basedir = File.join(home, '.local')
179
+ if gem_home.nil?
180
+ ENV['PATH'] = ENV['PATH'] + ":#{File.join(basedir, 'bin')}"
181
+ else
182
+ basedir = ENV['GEM_HOME']
183
+ end
184
+ FileUtils.mkdir_p File.join(basedir, 'bin')
185
+ FileUtils.mkdir_p File.join(basedir, 'lib')
186
+ destprefix = 'bin' if destprefix == '.'
187
+ install_location = File.join(basedir, destprefix, File.basename(src))
188
+ FileUtils.install(src, install_location, :mode => 0775)
158
189
  end
159
190
 
160
191
  end
@@ -1,3 +1,3 @@
1
1
  module Bindeps
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -34,8 +34,6 @@ module Unpacker
34
34
  def self.unpack(file, tmpdir = "/tmp", &block)
35
35
  Dir.mktmpdir 'unpacker' do |dir|
36
36
  cmd = case file
37
- when /rar$/
38
- "unrar x -y #{file} #{dir}"
39
37
  when /(tar|tgz|tar\.gz)$/
40
38
  "tar xzf #{file} --directory #{dir}"
41
39
  when /(tar\.bz|tbz|tar\.bz2)$/
@@ -58,31 +56,12 @@ module Unpacker
58
56
  end
59
57
 
60
58
  def self.archive?(file_name)
61
- supported = []
59
+ supported = Unpacker.supported_archives
62
60
  ext = File.extname(file_name).sub('.', '')
63
61
  return true if ext==""
64
- if !which('unrar').empty?
65
- supported << "rar"
66
- end
67
- if !which('tar').empty?
68
- %w[tar tgz tgz tar.gz tar.bz tar.bz2 tbz].each do |ext|
69
- supported << ext
70
- end
71
- end
72
- if !which('unzip').empty?
73
- supported << "zip"
74
- end
75
- if !which('gunzip').empty?
76
- supported << "gz"
77
- end
78
- if !which('bunzip2').empty?
79
- supported << "bz2"
80
- end
81
62
  support = supported.include? ext
82
63
  if !support
83
64
  help = case file_name
84
- when /rar$/
85
- "Please install unrar"
86
65
  when /(tar|tgz|tar\.gz|tar\.bz|tbz|tar\.bz2)$/
87
66
  "Please install tar"
88
67
  when /zip$/
@@ -102,8 +81,6 @@ module Unpacker
102
81
 
103
82
  def self.valid?(file_path, file_name = file_path)
104
83
  cmd = case file_name
105
- when /rar$/
106
- "unrar t #{file_path}"
107
84
  when /(tar|tar\.bz|tbz)$/
108
85
  "tar tf #{file_path}"
109
86
  when /zip$/
@@ -123,4 +100,26 @@ module Unpacker
123
100
  end
124
101
  end
125
102
 
103
+ def self.supported_archives
104
+ supported = []
105
+ if !which('unrar').empty?
106
+ supported << "rar"
107
+ end
108
+ if !which('tar').empty?
109
+ %w[tar tgz tgz tar.gz tar.bz tar.bz2 tbz].each do |ext|
110
+ supported << ext
111
+ end
112
+ end
113
+ if !which('unzip').empty?
114
+ supported << "zip"
115
+ end
116
+ if !which('gunzip').empty?
117
+ supported << "gz"
118
+ end
119
+ if !which('bunzip2').empty?
120
+ supported << "bz2"
121
+ end
122
+ supported
123
+ end
124
+
126
125
  end # module Unpacker
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Figure out where this script is located.
5
+ SELFDIR="`dirname \"$0\"`"
6
+ SELFDIR="`cd \"$SELFDIR\" && pwd`"
7
+
8
+ # Use the lib
9
+ cat "$SELFDIR/../lib/fakelib"
Binary file
@@ -0,0 +1,18 @@
1
+ fakelibbin:
2
+ binaries:
3
+ - fakelibbin
4
+ libraries:
5
+ - fakelib
6
+ version:
7
+ number: success
8
+ command: fakelibbin
9
+ url:
10
+ 64bit:
11
+ macosx: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
12
+ linux: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
13
+ unix: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
14
+ 32bit:
15
+ macosx: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
16
+ linux: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
17
+ unix: https://github.com/Blahah/bindeps/raw/master/test/data/fakelibbin.tgz
18
+ unpack: true
@@ -0,0 +1 @@
1
+ success
@@ -13,6 +13,7 @@ require 'shoulda-context'
13
13
  require 'bindeps'
14
14
 
15
15
  Turn.config.format = :pretty
16
- Turn.config.trace = 5
16
+ Turn.config.trace = 15
17
17
 
18
18
  require 'yaml'
19
+ require 'fileutils'
@@ -10,12 +10,20 @@ class TestBindeps < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  teardown do
13
- # delete fake binaries from
14
- bindir = File.join(ENV['GEM_HOME'], 'bin')
15
- `rm #{bindir}/fakebin` if File.exist?("#{bindir}/fakebin")
16
- `rm #{bindir}/fakebin2` if File.exist?("#{bindir}/fakebin2")
17
- `rm #{bindir}/fakebin3` if File.exist?("#{bindir}/fakebin3")
18
- `rm #{bindir}/fakebin4` if File.exist?("#{bindir}/fakebin4")
13
+ # delete fake binaries
14
+ bindirs = [File.join(ENV['HOME'], '.local', 'bin')]
15
+ if !ENV['GEM_HOME'].nil?
16
+ bindirs << File.join(ENV['GEM_HOME'], 'bin')
17
+ end
18
+ bindirs.each do |bindir|
19
+ %w[fakebin fakebin2 fakebin3 fakebin4 fakelibbin].each do |bin|
20
+ path = File.join(bindir, bin)
21
+ FileUtils.rm(path) if File.exist?(path)
22
+ end
23
+ # delete fake lib
24
+ libpath = File.expand_path File.join(bindir, '../lib/fakelib')
25
+ FileUtils.rm(libpath) if File.exist?(libpath)
26
+ end
19
27
  end
20
28
 
21
29
  should "identify and install missing dependencies" do
@@ -141,7 +149,34 @@ class TestBindeps < Test::Unit::TestCase
141
149
  config['version'],
142
150
  config['url'],
143
151
  config['unpack'])
144
- assert d.installed?('fakebin4'), "fakebin4 installed"
152
+ assert d.installed?('fakebin4'), "fakebin4 not installed"
153
+ end
154
+ end
155
+
156
+ should "install to a local directory if gem_home can't be found" do
157
+ ENV['GEM_HOME']=nil
158
+ test_yaml = File.join(@data_dir, 'fakebin.yaml')
159
+ Bindeps.require test_yaml
160
+ assert_equal 'success', `fakebin`.strip
161
+ test_yaml = File.join(@data_dir, 'fakebin2.yaml')
162
+ # install fakebin2
163
+ Bindeps.require test_yaml
164
+ msg = "this is a non-matching line\nfakebin v2.0.1\nmore non-matching stuff"
165
+ assert_equal msg, `fakebin2`.strip
166
+ end
167
+
168
+ should "handle lib dependencies" do
169
+ test_yaml = File.join(@data_dir, 'fakelibbin.yaml')
170
+ Bindeps.require test_yaml
171
+ deps = YAML.load_file test_yaml
172
+ deps.each_pair do |name, config|
173
+ d = Bindeps::Dependency.new(name,
174
+ config['binaries'],
175
+ config['version'],
176
+ config['url'],
177
+ config['unpack'],
178
+ config['libraries'])
179
+ assert d.installed?('fakelibbin'), "fakelibbin not installed"
145
180
  end
146
181
  end
147
182
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindeps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Smith-Unna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-07 00:00:00.000000000 Z
12
+ date: 2015-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fixwhich
@@ -176,6 +176,7 @@ files:
176
176
  - lib/bindeps.rb
177
177
  - lib/bindeps/version.rb
178
178
  - lib/unpacker.rb
179
+ - test/data/bin/fakelibbin
179
180
  - test/data/bowtie2_test.yaml
180
181
  - test/data/fakebin
181
182
  - test/data/fakebin.tgz
@@ -188,6 +189,9 @@ files:
188
189
  - test/data/fakebin3.yaml
189
190
  - test/data/fakebin4
190
191
  - test/data/fakebin4.yaml
192
+ - test/data/fakelibbin.tgz
193
+ - test/data/fakelibbin.yaml
194
+ - test/data/lib/fakelib
191
195
  - test/data/neverinstalled.yaml
192
196
  - test/data/wget
193
197
  - test/helper.rb
@@ -217,6 +221,7 @@ signing_key:
217
221
  specification_version: 4
218
222
  summary: binary dependency management for ruby gems
219
223
  test_files:
224
+ - test/data/bin/fakelibbin
220
225
  - test/data/bowtie2_test.yaml
221
226
  - test/data/fakebin
222
227
  - test/data/fakebin.tgz
@@ -229,6 +234,9 @@ test_files:
229
234
  - test/data/fakebin3.yaml
230
235
  - test/data/fakebin4
231
236
  - test/data/fakebin4.yaml
237
+ - test/data/fakelibbin.tgz
238
+ - test/data/fakelibbin.yaml
239
+ - test/data/lib/fakelib
232
240
  - test/data/neverinstalled.yaml
233
241
  - test/data/wget
234
242
  - test/helper.rb