bundler 0.9.0 → 0.9.1.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

@@ -4,7 +4,7 @@ require 'yaml'
4
4
  require 'bundler/rubygems'
5
5
 
6
6
  module Bundler
7
- VERSION = "0.9.0"
7
+ VERSION = "0.9.1.pre1"
8
8
 
9
9
  autoload :Definition, 'bundler/definition'
10
10
  autoload :Dependency, 'bundler/dependency'
@@ -14,6 +14,7 @@ module Bundler
14
14
  autoload :Installer, 'bundler/installer'
15
15
  autoload :RemoteSpecification, 'bundler/remote_specification'
16
16
  autoload :Resolver, 'bundler/resolver'
17
+ autoload :Runtime, 'bundler/runtime'
17
18
  autoload :Settings, 'bundler/settings'
18
19
  autoload :Source, 'bundler/source'
19
20
  autoload :Specification, 'bundler/specification'
@@ -62,9 +63,14 @@ module Bundler
62
63
  load(gemfile).setup(*groups)
63
64
  end
64
65
 
66
+ def require(*groups)
67
+ gemfile = default_gemfile
68
+ load(gemfile).require(*groups)
69
+ end
70
+
65
71
  def load(gemfile = default_gemfile)
66
72
  root = Pathname.new(gemfile).dirname
67
- Environment.new root, definition(gemfile)
73
+ Runtime.new root, definition(gemfile)
68
74
  end
69
75
 
70
76
  def definition(gemfile = default_gemfile)
@@ -125,4 +131,4 @@ module Bundler
125
131
  Gem.clear_paths
126
132
  end
127
133
  end
128
- end
134
+ end
@@ -56,6 +56,11 @@ module Bundler
56
56
 
57
57
  desc "lock", "Locks the bundle to the current set of dependencies, including all child dependencies."
58
58
  def lock
59
+ if File.exist?("#{Bundler.root}/Gemfile.lock")
60
+ Bundler.ui.info("The bundle is already locked, relocking.")
61
+ `rm #{Bundler.root}/Gemfile.lock`
62
+ end
63
+
59
64
  environment = Bundler.load
60
65
  environment.lock
61
66
  end
@@ -2,11 +2,15 @@ require 'rubygems/dependency'
2
2
 
3
3
  module Bundler
4
4
  class Dependency < Gem::Dependency
5
+ attr_reader :autorequire
6
+
5
7
  def initialize(name, version, options = {}, &blk)
6
8
  super(name, version)
7
9
 
8
- @group = options["group"] || :default
10
+ @groups = Array(options["group"] || :default)
9
11
  @source = options["source"]
12
+ @autorequire = options.include?("require") ? options['require'] || [] : [name]
13
+ @autorequire = [@autorequire] unless @autorequire.is_a?(Array)
10
14
  end
11
15
  end
12
- end
16
+ end
@@ -9,149 +9,23 @@ module Bundler
9
9
  @definition = definition
10
10
  end
11
11
 
12
- def setup(*groups)
13
- # Has to happen first
14
- cripple_rubygems
15
-
16
- # Activate the specs
17
- specs_for(*groups).each do |spec|
18
- Gem.loaded_specs[spec.name] = spec
19
- $LOAD_PATH.unshift(*spec.load_paths)
20
- end
21
- self
22
- end
23
-
24
- def dependencies
25
- @definition.actual_dependencies
26
- end
27
-
28
- def lock
29
- Bundler.ui.info("The bundle is already locked, relocking.") if locked?
30
- FileUtils.mkdir_p("#{root}/.bundle")
31
- write_yml_lock
32
- write_rb_lock
33
- Bundler.ui.info("The bundle is now locked. Use `bundle show` to list the gems in the environment.")
34
- end
35
-
36
- def unlock
37
- unless locked?
38
- Bundler.ui.info("The bundle is not currently locked.")
39
- return
40
- end
41
-
42
- FileUtils.rm_f("#{root}/.bundle/environment.rb")
43
- FileUtils.rm_f("#{root}/Gemfile.lock")
44
- Bundler.ui.info("The bundle is now unlocked. The dependencies may be changed.")
45
- end
46
-
47
- def locked?
48
- File.exist?("#{root}/Gemfile.lock")
49
- end
50
-
51
- def specs_for(*groups)
52
- return specs if groups.empty?
53
-
54
- dependencies = @definition.actual_dependencies.select { |d| groups.include?(d.group) }
55
- Resolver.resolve(dependencies, index)
56
- end
57
-
58
- def specs
59
- @specs ||= begin
60
- source_requirements = {}
61
- dependencies.each do |dep|
62
- next unless dep.source && dep.source.respond_to?(:local_specs)
63
- source_requirements[dep.name] = dep.source.local_specs
64
- end
65
-
66
- Resolver.resolve(@definition.actual_dependencies, index, source_requirements)
67
- end
68
- end
69
-
70
- alias gems specs
71
-
72
- def index
73
- @definition.local_index
74
- end
75
-
76
- def pack
77
- pack_path = "#{root}/vendor/cache/"
78
- FileUtils.mkdir_p(pack_path)
79
-
80
- Bundler.ui.info "Copying .gem files into vendor/cache"
81
- specs.each do |spec|
82
- next unless spec.source.is_a?(Source::SystemGems) || spec.source.is_a?(Source::Rubygems)
83
- possibilities = Gem.path.map { |p| "#{p}/cache/#{spec.full_name}.gem" }
84
- cached_path = possibilities.find { |p| File.exist? p }
85
- Bundler.ui.info " * #{File.basename(cached_path)}"
86
- next if File.expand_path(File.dirname(cached_path)) == File.expand_path(pack_path)
87
- FileUtils.cp(cached_path, pack_path)
88
- end
89
- end
90
-
91
12
  private
92
13
 
93
- def sources
94
- @definition.sources
95
- end
96
-
97
- def load_paths
98
- specs.map { |s| s.load_paths }.flatten
99
- end
100
-
101
- def cripple_rubygems
102
- # handle 1.9 where system gems are always on the load path
103
- if defined?(::Gem)
104
- me = File.expand_path("../../", __FILE__)
105
- $LOAD_PATH.reject! do |p|
106
- p != File.dirname(__FILE__) &&
107
- Gem.path.any? { |gp| p.include?(gp) }
108
- end
109
- $LOAD_PATH.unshift me
110
- $LOAD_PATH.uniq!
111
- end
112
-
113
- # Disable rubygems' gem activation system
114
- ::Kernel.class_eval do
115
- if private_method_defined?(:gem_original_require)
116
- alias rubygems_require require
117
- alias require gem_original_require
118
- end
119
-
120
- undef gem
121
- def gem(*)
122
- # Silently ignore calls to gem
123
- end
124
- end
125
- end
126
-
127
- def write_rb_lock
128
- template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
129
- erb = ERB.new(template, nil, '-')
130
- File.open("#{root}/.bundle/environment.rb", 'w') do |f|
131
- f.puts erb.result(binding)
14
+ def group_specs(specs)
15
+ dependencies.each do |d|
16
+ spec = specs.find { |s| s.name == d.name }
17
+ group_spec(specs, spec, d.groups)
132
18
  end
19
+ specs
133
20
  end
134
21
 
135
- def write_yml_lock
136
- yml = details.to_yaml
137
- File.open("#{root}/Gemfile.lock", 'w') do |f|
138
- f.puts yml
22
+ def group_spec(specs, spec, groups)
23
+ spec.groups.concat(groups)
24
+ spec.groups.uniq!
25
+ spec.dependencies.select { |d| d.type != :development }.each do |d|
26
+ spec = specs.find { |s| s.name == d.name }
27
+ group_spec(specs, spec, groups)
139
28
  end
140
29
  end
141
-
142
- def details
143
- details = {}
144
- details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} }
145
-
146
- details["specs"] = specs.map do |s|
147
- options = {"version" => s.version.to_s}
148
- options["source"] = sources.index(s.source) if sources.include?(s.source)
149
- { s.name => options }
150
- end
151
-
152
- details["dependencies"] = dependencies.map { |d| {d.name => d.version_requirements.to_s} }
153
- details
154
- end
155
-
156
30
  end
157
- end
31
+ end
@@ -1,18 +1,11 @@
1
1
  require 'rubygems/dependency_installer'
2
2
 
3
3
  module Bundler
4
- class Installer
4
+ class Installer < Environment
5
5
  def self.install(root, definition, options)
6
6
  new(root, definition).run(options)
7
7
  end
8
8
 
9
- attr_reader :root
10
-
11
- def initialize(root, definition)
12
- @root = root
13
- @definition = definition
14
- end
15
-
16
9
  def run(options)
17
10
  if dependencies.empty?
18
11
  Bundler.ui.warn "The Gemfile specifies no dependencies"
@@ -82,23 +75,6 @@ module Bundler
82
75
  specs
83
76
  end
84
77
 
85
- def group_specs(specs)
86
- dependencies.each do |d|
87
- spec = specs.find { |s| s.name == d.name }
88
- group_spec(specs, spec, d.group)
89
- end
90
- specs
91
- end
92
-
93
- def group_spec(specs, spec, group)
94
- spec.groups << group
95
- spec.groups.uniq!
96
- spec.dependencies.select { |d| d.type != :development }.each do |d|
97
- spec = specs.find { |s| s.name == d.name }
98
- group_spec(specs, spec, group)
99
- end
100
- end
101
-
102
78
  def ambiguous?(dep)
103
79
  dep.version_requirements.requirements.any? { |op,_| op != '=' }
104
80
  end
@@ -17,6 +17,6 @@ module Gem
17
17
  end
18
18
 
19
19
  class Dependency
20
- attr_accessor :source, :group
20
+ attr_accessor :source, :groups
21
21
  end
22
- end
22
+ end
@@ -0,0 +1,189 @@
1
+ module Bundler
2
+ class Runtime < Environment
3
+ def setup(*groups)
4
+ # Has to happen first
5
+ cripple_rubygems
6
+
7
+ # Activate the specs
8
+ specs_for(*groups).each do |spec|
9
+ Gem.loaded_specs[spec.name] = spec
10
+ $LOAD_PATH.unshift(*spec.load_paths)
11
+ end
12
+ self
13
+ end
14
+
15
+ def require(*groups)
16
+ groups = [:default] if groups.empty?
17
+ autorequires = autorequires_for_groups(*groups)
18
+ groups.each do |group|
19
+ (autorequires[group] || []).each do |path|
20
+ Kernel.require(path)
21
+ end
22
+ end
23
+ end
24
+
25
+ def dependencies
26
+ @definition.actual_dependencies
27
+ end
28
+
29
+ def lock
30
+ FileUtils.mkdir_p("#{root}/.bundle")
31
+ write_yml_lock
32
+ write_rb_lock
33
+ Bundler.ui.info("The bundle is now locked. Use `bundle show` to list the gems in the environment.")
34
+ end
35
+
36
+ def unlock
37
+ unless locked?
38
+ Bundler.ui.info("The bundle is not currently locked.")
39
+ return
40
+ end
41
+
42
+ FileUtils.rm_f("#{root}/.bundle/environment.rb")
43
+ FileUtils.rm_f("#{root}/Gemfile.lock")
44
+ Bundler.ui.info("The bundle is now unlocked. The dependencies may be changed.")
45
+ end
46
+
47
+ def lock
48
+ Bundler.ui.info("The bundle is already locked, relocking.") if locked?
49
+ sources.each { |s| s.lock if s.respond_to?(:lock) }
50
+ FileUtils.mkdir_p("#{root}/.bundle")
51
+ write_yml_lock
52
+ write_rb_lock
53
+ Bundler.ui.info("The bundle is now locked. Use `bundle show` to list the gems in the environment.")
54
+ end
55
+
56
+ def locked?
57
+ File.exist?("#{root}/Gemfile.lock")
58
+ end
59
+
60
+ def dependencies_for(*groups)
61
+ if groups.empty?
62
+ dependencies
63
+ else
64
+ dependencies.select { |d| (groups & d.groups).any? }
65
+ end
66
+ end
67
+
68
+ def specs_for(*groups)
69
+ if groups.empty?
70
+ specs
71
+ else
72
+ Resolver.resolve(dependencies_for(*groups), index)
73
+ end
74
+ end
75
+
76
+ def specs
77
+ @specs ||= begin
78
+ source_requirements = {}
79
+ dependencies.each do |dep|
80
+ next unless dep.source && dep.source.respond_to?(:local_specs)
81
+ source_requirements[dep.name] = dep.source.local_specs
82
+ end
83
+
84
+ Resolver.resolve(@definition.actual_dependencies, index, source_requirements)
85
+ end
86
+ end
87
+
88
+ alias gems specs
89
+
90
+ def index
91
+ @definition.local_index
92
+ end
93
+
94
+ def pack
95
+ pack_path = "#{root}/vendor/cache/"
96
+ FileUtils.mkdir_p(pack_path)
97
+
98
+ Bundler.ui.info "Copying .gem files into vendor/cache"
99
+ specs.each do |spec|
100
+ next unless spec.source.is_a?(Source::SystemGems) || spec.source.is_a?(Source::Rubygems)
101
+ possibilities = Gem.path.map { |p| "#{p}/cache/#{spec.full_name}.gem" }
102
+ cached_path = possibilities.find { |p| File.exist? p }
103
+ Bundler.ui.info " * #{File.basename(cached_path)}"
104
+ next if File.expand_path(File.dirname(cached_path)) == File.expand_path(pack_path)
105
+ FileUtils.cp(cached_path, pack_path)
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def sources
112
+ @definition.sources
113
+ end
114
+
115
+ def load_paths
116
+ specs.map { |s| s.load_paths }.flatten
117
+ end
118
+
119
+ def cripple_rubygems
120
+ # handle 1.9 where system gems are always on the load path
121
+ if defined?(::Gem)
122
+ me = File.expand_path("../../", __FILE__)
123
+ $LOAD_PATH.reject! do |p|
124
+ p != File.dirname(__FILE__) &&
125
+ Gem.path.any? { |gp| p.include?(gp) }
126
+ end
127
+ $LOAD_PATH.unshift me
128
+ $LOAD_PATH.uniq!
129
+ end
130
+
131
+ # Disable rubygems' gem activation system
132
+ ::Kernel.class_eval do
133
+ if private_method_defined?(:gem_original_require)
134
+ alias rubygems_require require
135
+ alias require gem_original_require
136
+ end
137
+
138
+ undef gem
139
+ def gem(*)
140
+ # Silently ignore calls to gem
141
+ end
142
+ end
143
+ end
144
+
145
+ def write_rb_lock
146
+ template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
147
+ erb = ERB.new(template, nil, '-')
148
+ File.open("#{root}/.bundle/environment.rb", 'w') do |f|
149
+ f.puts erb.result(binding)
150
+ end
151
+ end
152
+
153
+ def write_yml_lock
154
+ yml = details.to_yaml
155
+ File.open("#{root}/Gemfile.lock", 'w') do |f|
156
+ f.puts yml
157
+ end
158
+ end
159
+
160
+ def details
161
+ details = {}
162
+ details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} }
163
+
164
+ details["specs"] = specs.map do |s|
165
+ options = {"version" => s.version.to_s}
166
+ options["source"] = sources.index(s.source) if sources.include?(s.source)
167
+ { s.name => options }
168
+ end
169
+
170
+ details["dependencies"] = @definition.dependencies.map { |d| {d.name => d.version_requirements.to_s} }
171
+ details
172
+ end
173
+
174
+ def autorequires_for_groups(*groups)
175
+ autorequires = Hash.new { |h,k| h[k] = [] }
176
+ @definition.dependencies.each do |dep|
177
+ dep.groups.each do |group|
178
+ autorequires[group].concat dep.autorequire
179
+ end
180
+ end
181
+
182
+ if groups.empty?
183
+ autorequires
184
+ else
185
+ groups.inject({}) { |h,g| h[g] = autorequires[g]; h }
186
+ end
187
+ end
188
+ end
189
+ end
@@ -180,7 +180,7 @@ module Bundler
180
180
  end
181
181
 
182
182
  class Git < Path
183
- attr_reader :uri, :ref
183
+ attr_reader :uri, :ref, :options
184
184
 
185
185
  def initialize(options)
186
186
  @options = options
@@ -194,10 +194,6 @@ module Bundler
194
194
  "#{@uri} (at #{ref})"
195
195
  end
196
196
 
197
- def options
198
- @options.merge("ref" => revision)
199
- end
200
-
201
197
  def path
202
198
  Bundler.install_path.join("#{base_name}-#{uri_hash}-#{ref}")
203
199
  end
@@ -239,18 +235,16 @@ module Bundler
239
235
  Bundler.ui.debug " * Already checked out revision: #{ref}"
240
236
  else
241
237
  Bundler.ui.debug " * Checking out revision: #{ref}"
242
- FileUtils.mkdir_p(path)
243
- Dir.chdir(path) do
244
- unless File.exist?(".git")
245
- %x(git clone --no-checkout #{cache_path} #{path})
246
- end
247
- git "fetch --quiet"
248
- git "reset --hard #{revision}"
249
- end
238
+ checkout
250
239
  @installed = true
251
240
  end
252
241
  end
253
242
 
243
+ def lock
244
+ @ref = @options["ref"] = revision
245
+ checkout
246
+ end
247
+
254
248
  private
255
249
 
256
250
  def git(command)
@@ -284,6 +278,17 @@ module Bundler
284
278
  end
285
279
  end
286
280
 
281
+ def checkout
282
+ FileUtils.mkdir_p(path)
283
+ Dir.chdir(path) do
284
+ unless File.exist?(".git")
285
+ %x(git clone --no-checkout #{cache_path} #{path})
286
+ end
287
+ git "fetch --quiet"
288
+ git "reset --hard #{revision}"
289
+ end
290
+ end
291
+
287
292
  def revision
288
293
  @revision ||= in_cache { git("rev-parse #{ref}").strip }
289
294
  end
@@ -1,6 +1,19 @@
1
1
  # DO NOT MODIFY THIS FILE
2
2
  module Bundler
3
- <% load_paths.each do |path| -%>
4
- $LOAD_PATH.unshift "<%= path %>"
5
- <% end -%>
6
- end
3
+ LOAD_PATHS = <%= load_paths.inspect %>
4
+ AUTOREQUIRES = <%= autorequires_for_groups.inspect %>
5
+
6
+ def self.setup(*groups)
7
+ LOAD_PATHS.each { |path| $LOAD_PATH.unshift path }
8
+ end
9
+
10
+ def self.require(*groups)
11
+ groups = [:default] if groups.empty?
12
+ groups.each do |group|
13
+ AUTOREQUIRES[group].each { |file| Kernel.require file }
14
+ end
15
+ end
16
+
17
+ # Setup bundle when it's required.
18
+ setup
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Lerche
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-03 00:00:00 -08:00
13
+ date: 2010-02-04 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -35,6 +35,7 @@ files:
35
35
  - lib/bundler/remote_specification.rb
36
36
  - lib/bundler/resolver.rb
37
37
  - lib/bundler/rubygems.rb
38
+ - lib/bundler/runtime.rb
38
39
  - lib/bundler/settings.rb
39
40
  - lib/bundler/setup.rb
40
41
  - lib/bundler/source.rb
@@ -67,7 +68,7 @@ has_rdoc: true
67
68
  homepage: http://github.com/carlhuda/bundler
68
69
  licenses: []
69
70
 
70
- post_install_message:
71
+ post_install_message: Due to a rubygems bug, you must uninstall all older versions of bundler for 0.9 to work
71
72
  rdoc_options: []
72
73
 
73
74
  require_paths: