bundler_ext 0.3.1 → 0.3.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 +4 -4
- data/CHANGELOG +7 -0
- data/README.md +5 -5
- data/lib/bundler_ext/bundler_ext.rb +58 -23
- data/lib/bundler_ext/version.rb +1 -1
- data/spec/bundler_ext/bundler_ext_spec.rb +88 -21
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18929e0e577a996fe29aab583a44ff3dc47f70ee
|
4
|
+
data.tar.gz: 8b5fc498ef3304ec5370c3a79226e764514a6f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6947df0c40f5c52fe75e5fc194b40278449485255205e6961a1d09026693c166b7d88e3ac877d7ac9cf276287c78d0e0279600439909db26b868da7d261d23d8
|
7
|
+
data.tar.gz: 171b367e5382260a075546f96ce30cf600fa67b6981013a21dff99a7e1326fd173e5dcc62db343b901eff484eef12fdfe355e115c438300efb362613c423b239
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
====== version 0.3.2 =========
|
2
|
+
|
3
|
+
Mo Morsi (2013-11-19)
|
4
|
+
- 12b79e0 Shorten default ENV variable names to 'BEXT'
|
5
|
+
Mo Morsi (2013-11-12)
|
6
|
+
- ad57f28 Lookup and activate versions of system installed gems
|
7
|
+
|
1
8
|
====== version 0.3.1 =========
|
2
9
|
|
3
10
|
Jason Guiditta (2013-07-22)
|
data/README.md
CHANGED
@@ -59,21 +59,21 @@ case, this is not the desired behavior, we explicitly want to say
|
|
59
59
|
There are special environment variables you can use. You may need to
|
60
60
|
insert additional groups to be required, e.g. when developing and you
|
61
61
|
want to restart the system in development mode once. Use
|
62
|
-
|
62
|
+
BEXT_GROUPS variable (separate with whitespace):
|
63
63
|
|
64
|
-
|
64
|
+
BEXT_GROUPS="group1 group2 group3" rails server ...
|
65
65
|
|
66
66
|
Also, by default bundler_ext raises an error when dependency cannot
|
67
67
|
be loaded. You can turn off this behavior (e.g. for installers when
|
68
|
-
you want to do rake db:migrate) with setting
|
68
|
+
you want to do rake db:migrate) with setting BEXT_NOSTRICT:
|
69
69
|
|
70
|
-
|
70
|
+
BEXT_NOSTRICT=1 rake db:migrate ...
|
71
71
|
|
72
72
|
In this mode bundler_ext prints out error messages on the stdout,
|
73
73
|
but does not terminate the process.
|
74
74
|
|
75
75
|
Some rubygems require HOME environment variable to be set, threfore
|
76
|
-
not running daemonized. For this purposes there is
|
76
|
+
not running daemonized. For this purposes there is BEXT_HOME
|
77
77
|
variable which can be used to set HOME environment variable before
|
78
78
|
any rubygem gets loaded. The variable is not exported for
|
79
79
|
subprocesses.
|
@@ -1,30 +1,43 @@
|
|
1
1
|
require "bundler"
|
2
2
|
|
3
3
|
# some rubygems does not play well with daemonized processes ($HOME is empty)
|
4
|
+
ENV['HOME'] = ENV['BEXT_HOME'] if ENV['BEXT_HOME']
|
4
5
|
ENV['HOME'] = ENV['BUNDLER_EXT_HOME'] if ENV['BUNDLER_EXT_HOME']
|
5
6
|
|
6
7
|
class BundlerExt
|
7
8
|
def self.parse_from_gemfile(gemfile,*groups)
|
8
9
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
9
10
|
extra_groups = ENV['BUNDLER_EXT_GROUPS']
|
11
|
+
extra_groups = ENV['BEXT_GROUPS'] || ENV['BUNDLER_EXT_GROUPS']
|
10
12
|
extra_groups.split(/\s/).each {|g| groups << g.to_sym} if extra_groups
|
11
13
|
all_groups = false
|
12
14
|
all_groups = true if groups.size == 1 and groups.include?(:all) and not extra_groups
|
13
15
|
groups.map! { |g| g.to_sym }
|
14
16
|
g = Bundler::Dsl.evaluate(gemfile,'foo',true)
|
15
|
-
|
17
|
+
deps = {}
|
16
18
|
g.dependencies.each do |dep|
|
17
19
|
if ((groups & dep.groups).any? || all_groups) && dep.current_platform?
|
20
|
+
files = []
|
18
21
|
Array(dep.autorequire || dep.name).each do |file|
|
19
|
-
|
22
|
+
files << file
|
20
23
|
end
|
24
|
+
deps[dep.name] = {:dep => dep, :files => files}
|
21
25
|
end
|
22
26
|
end
|
23
|
-
|
27
|
+
deps
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.system_gem_name_for(name)
|
31
|
+
ENV['BEXT_PKG_PREFIX'] ||= ''
|
32
|
+
"#{ENV['BEXT_PKG_PREFIX']}#{name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.system_gem_version_for(name)
|
36
|
+
LinuxAdmin::Package.get_info(name)['version']
|
24
37
|
end
|
25
38
|
|
26
39
|
def self.strict_error(msg)
|
27
|
-
if ENV['BUNDLER_EXT_NOSTRICT']
|
40
|
+
if ENV['BEXT_NOSTRICT'] || ENV['BUNDLER_EXT_NOSTRICT']
|
28
41
|
puts msg
|
29
42
|
else
|
30
43
|
raise msg
|
@@ -32,28 +45,50 @@ class BundlerExt
|
|
32
45
|
end
|
33
46
|
|
34
47
|
def self.system_require(gemfile,*groups)
|
35
|
-
|
36
|
-
|
48
|
+
activate_versions = ENV['BEXT_ACTIVATE_VERSIONS']
|
49
|
+
if activate_versions
|
37
50
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
require "linux_admin"
|
52
|
+
rescue LoadError
|
53
|
+
puts "linux_admin not installed, cannot retrieve versions to activate"
|
54
|
+
activate_versions = false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
BundlerExt.parse_from_gemfile(gemfile,*groups).each do |name,gdep|
|
59
|
+
# activate the dependency
|
60
|
+
if activate_versions
|
61
|
+
begin
|
62
|
+
sys_name = BundlerExt.system_gem_name_for(name)
|
63
|
+
version = BundlerExt.system_gem_version_for(sys_name)
|
64
|
+
gem name, "=#{version}"
|
65
|
+
rescue LoadError, CommandResultError
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
gdep[:files].each do |dep|
|
70
|
+
#This part ripped wholesale from lib/bundler/runtime.rb (github/master)
|
71
|
+
begin
|
72
|
+
#puts "Attempting to require #{dep}"
|
73
|
+
require dep
|
74
|
+
rescue LoadError => e
|
75
|
+
#puts "Caught error: #{e.message}"
|
76
|
+
if dep.include?('-')
|
77
|
+
begin
|
78
|
+
if dep.respond_to? :name
|
79
|
+
namespaced_file = dep.name.gsub('-', '/')
|
80
|
+
else
|
81
|
+
# try to load unresolved deps
|
82
|
+
namespaced_file = dep.gsub('-', '/')
|
83
|
+
end
|
84
|
+
#puts "Munged the name, now trying to require as #{namespaced_file}"
|
85
|
+
require namespaced_file
|
86
|
+
rescue LoadError => e2
|
87
|
+
strict_error "Gem loading error: #{e2.message}"
|
49
88
|
end
|
50
|
-
|
51
|
-
|
52
|
-
rescue LoadError => e2
|
53
|
-
strict_error "Gem loading error: #{e2.message}"
|
89
|
+
else
|
90
|
+
strict_error "Gem loading error: #{e.message}"
|
54
91
|
end
|
55
|
-
else
|
56
|
-
strict_error "Gem loading error: #{e.message}"
|
57
92
|
end
|
58
93
|
end
|
59
94
|
end
|
data/lib/bundler_ext/version.rb
CHANGED
@@ -1,57 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# skip system specs unless we can load linux_admin
|
4
|
+
skip_system = false
|
5
|
+
begin
|
6
|
+
require 'linux_admin'
|
7
|
+
rescue LoadError
|
8
|
+
skip_system = true
|
9
|
+
end
|
10
|
+
|
3
11
|
describe BundlerExt do
|
4
12
|
before(:each) do
|
5
13
|
@gemfile = 'spec/fixtures/Gemfile.in'
|
6
14
|
end
|
7
15
|
after(:each) do
|
8
|
-
ENV['
|
9
|
-
ENV['
|
16
|
+
ENV['BUNDLER_PKG_PREFIX'] = nil
|
17
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = nil
|
18
|
+
ENV['BEXT_PKG_PREFIX'] = nil
|
19
|
+
ENV['BEXT_NOSTRICT'] = nil
|
20
|
+
ENV['BEXT_GROUPS'] = nil
|
10
21
|
end
|
11
22
|
|
12
23
|
describe "#parse_from_gemfile" do
|
13
24
|
describe "with no group passed in" do
|
14
25
|
it "should return nothing to require" do
|
15
26
|
libs = BundlerExt.parse_from_gemfile(@gemfile)
|
16
|
-
libs.should be_an(
|
17
|
-
libs.should_not include('deltacloud')
|
18
|
-
libs.should_not include('vcr')
|
27
|
+
libs.should be_an(Hash)
|
28
|
+
libs.keys.should_not include('deltacloud-client')
|
29
|
+
libs.keys.should_not include('vcr')
|
19
30
|
end
|
20
31
|
end
|
21
32
|
describe "with :all passed in" do
|
22
33
|
it "should return the list of system libraries in all groups to require" do
|
23
34
|
libs = BundlerExt.parse_from_gemfile(@gemfile, :all)
|
24
|
-
libs.should be_an(
|
25
|
-
libs.should include('deltacloud')
|
26
|
-
libs.should
|
35
|
+
libs.should be_an(Hash)
|
36
|
+
libs.keys.should include('deltacloud-client')
|
37
|
+
libs['deltacloud-client'][:files].should == ['deltacloud']
|
38
|
+
libs.keys.should include('vcr')
|
27
39
|
end
|
28
40
|
end
|
29
41
|
describe "with group passed in" do
|
30
42
|
it "should not return any deps that are not in the 'development' group" do
|
31
43
|
libs = BundlerExt.parse_from_gemfile(@gemfile,'development')
|
32
|
-
libs.should be_an(
|
33
|
-
libs.should_not include('deltacloud')
|
44
|
+
libs.should be_an(Hash)
|
45
|
+
libs.keys.should_not include('deltacloud-client')
|
34
46
|
end
|
35
47
|
it "should return only deps that are in the :test group" do
|
36
48
|
libs = BundlerExt.parse_from_gemfile(@gemfile, :test)
|
37
|
-
libs.should be_an(
|
38
|
-
libs.should_not include('deltacloud')
|
39
|
-
libs.should include('vcr')
|
49
|
+
libs.should be_an(Hash)
|
50
|
+
libs.keys.should_not include('deltacloud-client')
|
51
|
+
libs.keys.should include('vcr')
|
40
52
|
end
|
41
53
|
it "should return deps from both the :default and :test groups" do
|
42
54
|
libs = BundlerExt.parse_from_gemfile(@gemfile, :default, :test)
|
43
|
-
libs.should be_an(
|
44
|
-
libs.should include('deltacloud')
|
45
|
-
libs.should include('vcr')
|
55
|
+
libs.should be_an(Hash)
|
56
|
+
libs.keys.should include('deltacloud-client')
|
57
|
+
libs.keys.should include('vcr')
|
46
58
|
end
|
47
59
|
end
|
48
60
|
it "should only return deps for the current platform" do
|
49
61
|
libs = BundlerExt.parse_from_gemfile(@gemfile)
|
50
|
-
libs.should be_an(
|
62
|
+
libs.should be_an(Hash)
|
51
63
|
if RUBY_VERSION < "1.9"
|
52
|
-
libs.should_not include('cinch')
|
64
|
+
libs.keys.should_not include('cinch')
|
53
65
|
else
|
54
|
-
libs.should_not include('fastercsv')
|
66
|
+
libs.keys.should_not include('fastercsv')
|
55
67
|
end
|
56
68
|
end
|
57
69
|
end
|
@@ -59,21 +71,76 @@ require 'spec_helper'
|
|
59
71
|
it "strict mode should fail loading non existing gem" do
|
60
72
|
expect { BundlerExt.system_require(@gemfile, :fail) }.to raise_error
|
61
73
|
end
|
74
|
+
|
75
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
76
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
77
|
+
BundlerExt.system_require(@gemfile)
|
78
|
+
defined?(Gem).should be_true
|
79
|
+
end
|
80
|
+
|
62
81
|
it "non-strict mode should load the libraries in the gemfile" do
|
63
82
|
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
64
83
|
BundlerExt.system_require(@gemfile)
|
65
84
|
defined?(Gem).should be_true
|
66
85
|
end
|
86
|
+
|
87
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
88
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
89
|
+
BundlerExt.system_require(@gemfile, :fail)
|
90
|
+
defined?(Gem).should be_true
|
91
|
+
end
|
92
|
+
|
67
93
|
it "non-strict mode should load the libraries in the gemfile" do
|
68
94
|
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
69
95
|
BundlerExt.system_require(@gemfile, :fail)
|
70
96
|
defined?(Gem).should be_true
|
71
97
|
end
|
72
98
|
it "non-strict mode should load the libraries using env var list" do
|
73
|
-
ENV['
|
74
|
-
ENV['
|
99
|
+
ENV['BEXT_GROUPS'] = 'test development blah'
|
100
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
101
|
+
BundlerExt.system_require(@gemfile)
|
102
|
+
defined?(Gem::Command).should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "non-strict mode should load the libraries using env var list" do
|
106
|
+
ENV['BUNLDER_EXT_GROUPS'] = 'test development blah'
|
107
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
75
108
|
BundlerExt.system_require(@gemfile)
|
76
109
|
defined?(Gem::Command).should be_true
|
77
110
|
end
|
111
|
+
|
112
|
+
unless skip_system
|
113
|
+
context "ENV['BEXT_ACTIVATE_VERSIONS'] is true" do
|
114
|
+
before(:each) do
|
115
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
116
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = 'true'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "activates the version of the system installed package" do
|
120
|
+
gems = BundlerExt.parse_from_gemfile(@gemfile, :all)
|
121
|
+
gems.each { |gem,gdep|
|
122
|
+
version = rand(100)
|
123
|
+
BundlerExt.should_receive(:system_gem_name_for).with(gem).
|
124
|
+
and_return(gem)
|
125
|
+
BundlerExt.should_receive(:system_gem_version_for).with(gem).
|
126
|
+
and_return(version)
|
127
|
+
BundlerExt.should_receive(:gem).with(gem, "=#{version}")
|
128
|
+
}
|
129
|
+
BundlerExt.system_require(@gemfile, :all)
|
130
|
+
end
|
131
|
+
|
132
|
+
context "ENV['BEXT_PKG_PREFIX'] is specified" do
|
133
|
+
it "prepends bundler pkg prefix onto system package name to load" do
|
134
|
+
ENV['BEXT_PKG_PREFIX'] = 'rubygem-'
|
135
|
+
gems = BundlerExt.parse_from_gemfile(@gemfile, :all)
|
136
|
+
gems.each { |gem,gdep|
|
137
|
+
BundlerExt.should_receive(:system_gem_version_for).with("rubygem-#{gem}").
|
138
|
+
and_return('0')
|
139
|
+
}
|
140
|
+
BundlerExt.system_require(@gemfile, :all)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
78
145
|
end
|
79
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundler_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Guiditta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,9 +75,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- - '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
requirements:
|
78
|
+
requirements:
|
79
|
+
- Install the linux_admin gem and set BEXT_ACTIVATE_VERSIONS to true to activate rpm/deb
|
80
|
+
installed gems
|
79
81
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.0.
|
82
|
+
rubygems_version: 2.0.13
|
81
83
|
signing_key:
|
82
84
|
specification_version: 4
|
83
85
|
summary: Load system gems via Bundler DSL
|