bundler 0.8.1 → 0.9.0.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.

Files changed (58) hide show
  1. data/README +7 -0
  2. data/bin/bundle +3 -0
  3. data/lib/bundler.rb +72 -37
  4. data/lib/bundler/cli.rb +64 -68
  5. data/lib/bundler/definition.rb +78 -0
  6. data/lib/bundler/dependency.rb +7 -57
  7. data/lib/bundler/dsl.rb +42 -142
  8. data/lib/bundler/environment.rb +94 -54
  9. data/lib/bundler/index.rb +98 -0
  10. data/lib/bundler/installer.rb +137 -0
  11. data/lib/bundler/remote_specification.rb +1 -1
  12. data/lib/bundler/resolver.rb +20 -50
  13. data/lib/bundler/rubygems.rb +22 -0
  14. data/lib/bundler/source.rb +185 -295
  15. data/lib/bundler/specification.rb +22 -0
  16. data/lib/bundler/templates/Gemfile +4 -0
  17. data/lib/bundler/templates/environment.erb +3 -153
  18. data/lib/bundler/ui.rb +51 -0
  19. data/lib/bundler/vendor/thor.rb +241 -0
  20. data/lib/bundler/vendor/thor/actions.rb +274 -0
  21. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  22. data/lib/bundler/vendor/thor/actions/directory.rb +91 -0
  23. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  24. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +223 -0
  25. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +101 -0
  26. data/lib/bundler/vendor/thor/base.rb +515 -0
  27. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  28. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  29. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  30. data/lib/bundler/vendor/thor/error.rb +27 -0
  31. data/lib/bundler/vendor/thor/group.rb +267 -0
  32. data/lib/bundler/vendor/thor/invocation.rb +178 -0
  33. data/lib/bundler/vendor/thor/parser.rb +4 -0
  34. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  35. data/lib/bundler/vendor/thor/parser/arguments.rb +145 -0
  36. data/lib/bundler/vendor/thor/parser/option.rb +132 -0
  37. data/lib/bundler/vendor/thor/parser/options.rb +142 -0
  38. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  39. data/lib/bundler/vendor/thor/runner.rb +303 -0
  40. data/lib/bundler/vendor/thor/shell.rb +78 -0
  41. data/lib/bundler/vendor/thor/shell/basic.rb +239 -0
  42. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  43. data/lib/bundler/vendor/thor/task.rb +111 -0
  44. data/lib/bundler/vendor/thor/util.rb +233 -0
  45. data/lib/bundler/vendor/thor/version.rb +3 -0
  46. metadata +48 -26
  47. data/README.markdown +0 -284
  48. data/Rakefile +0 -81
  49. data/lib/bundler/bundle.rb +0 -314
  50. data/lib/bundler/commands/bundle_command.rb +0 -72
  51. data/lib/bundler/commands/exec_command.rb +0 -36
  52. data/lib/bundler/finder.rb +0 -51
  53. data/lib/bundler/gem_bundle.rb +0 -11
  54. data/lib/bundler/gem_ext.rb +0 -34
  55. data/lib/bundler/runtime.rb +0 -2
  56. data/lib/bundler/templates/app_script.erb +0 -3
  57. data/lib/bundler/templates/environment_picker.erb +0 -4
  58. data/lib/rubygems_plugin.rb +0 -6
@@ -0,0 +1,22 @@
1
+ module Bundler
2
+ class Specification < Gem::Specification
3
+ attr_accessor :relative_loaded_from
4
+
5
+ def self.from_gemspec(gemspec)
6
+ spec = allocate
7
+ gemspec.instance_variables.each do |ivar|
8
+ spec.instance_variable_set(ivar, gemspec.instance_variable_get(ivar))
9
+ end
10
+ spec
11
+ end
12
+
13
+ def loaded_from
14
+ return super unless relative_loaded_from
15
+ source.path.join(relative_loaded_from)
16
+ end
17
+
18
+ def full_gem_path
19
+ loaded_from.dirname.expand_path
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source :gemcutter
3
+ #
4
+ # gem "rails"
@@ -1,156 +1,6 @@
1
1
  # DO NOT MODIFY THIS FILE
2
2
  module Bundler
3
- file = File.expand_path(__FILE__)
4
- dir = File.dirname(file)
5
-
6
- <% unless system_gems? -%>
7
- ENV["GEM_HOME"] = dir
8
- ENV["GEM_PATH"] = dir
9
-
10
- # handle 1.9 where system gems are always on the load path
11
- if defined?(::Gem)
12
- $LOAD_PATH.reject! do |p|
13
- p != File.dirname(__FILE__) &&
14
- Gem.path.any? { |gp| p.include?(gp) }
15
- end
16
- end
17
-
18
- <% end -%>
19
- ENV["PATH"] = "#{dir}/<%= bindir %><%= File::PATH_SEPARATOR %>#{ENV["PATH"]}"
20
- ENV["RUBYOPT"] = "-r#{file} #{ENV["RUBYOPT"]}"
21
-
22
- <% load_paths.each do |load_path| -%>
23
- $LOAD_PATH.unshift File.expand_path("#{dir}/<%= load_path %>")
24
- <% end -%>
25
-
26
- @gemfile = "#{dir}/<%= filename %>"
27
-
28
- <% if rubygems? -%>
29
- require "rubygems" unless respond_to?(:gem) # 1.9 already has RubyGems loaded
30
-
31
- @bundled_specs = {}
32
- <% specs.each do |spec| -%>
33
- <% if spec.no_bundle? -%>
34
- gem "<%= spec.name %>", "<%= spec.version %>"
35
- <% else -%>
36
- <% path = spec_file_for(spec) -%>
37
- @bundled_specs["<%= spec.name %>"] = eval(File.read("#{dir}/<%= path %>"))
38
- @bundled_specs["<%= spec.name %>"].loaded_from = "#{dir}/<%= path %>"
39
- <% end -%>
40
- <% end -%>
41
-
42
- def self.add_specs_to_loaded_specs
43
- Gem.loaded_specs.merge! @bundled_specs
44
- end
45
-
46
- def self.add_specs_to_index
47
- @bundled_specs.each do |name, spec|
48
- Gem.source_index.add_spec spec
49
- end
50
- end
51
-
52
- add_specs_to_loaded_specs
53
- add_specs_to_index
54
- <% end -%>
55
-
56
- def self.require_env(env = nil)
57
- context = Class.new do
58
- def initialize(env) @env = env && env.to_s ; end
59
- def method_missing(*) ; yield if block_given? ; end
60
- def only(*env)
61
- old, @only = @only, _combine_only(env.flatten)
62
- yield
63
- @only = old
64
- end
65
- def except(*env)
66
- old, @except = @except, _combine_except(env.flatten)
67
- yield
68
- @except = old
69
- end
70
- def gem(name, *args)
71
- opt = args.last.is_a?(Hash) ? args.pop : {}
72
- only = _combine_only(opt[:only] || opt["only"])
73
- except = _combine_except(opt[:except] || opt["except"])
74
- files = opt[:require_as] || opt["require_as"] || name
75
- files = [files] unless files.respond_to?(:each)
76
-
77
- return unless !only || only.any? {|e| e == @env }
78
- return if except && except.any? {|e| e == @env }
79
-
80
- if files = opt[:require_as] || opt["require_as"]
81
- files = Array(files)
82
- files.each { |f| require f }
83
- else
84
- begin
85
- require name
86
- rescue LoadError
87
- # Do nothing
88
- end
89
- end
90
- yield if block_given?
91
- true
92
- end
93
- private
94
- def _combine_only(only)
95
- return @only unless only
96
- only = [only].flatten.compact.uniq.map { |o| o.to_s }
97
- only &= @only if @only
98
- only
99
- end
100
- def _combine_except(except)
101
- return @except unless except
102
- except = [except].flatten.compact.uniq.map { |o| o.to_s }
103
- except |= @except if @except
104
- except
105
- end
106
- end
107
- context.new(env && env.to_s).instance_eval(File.read(@gemfile), @gemfile, 1)
108
- end
109
- end
110
-
111
- <% if rubygems? -%>
112
- module Gem
113
- @loaded_stacks = Hash.new { |h,k| h[k] = [] }
114
-
115
- def source_index.refresh!
116
- super
117
- Bundler.add_specs_to_index
118
- end
119
- end
120
- <% else -%>
121
- $" << "rubygems.rb"
122
-
123
- module Kernel
124
- def gem(*)
125
- # Silently ignore calls to gem, since, in theory, everything
126
- # is activated correctly already.
127
- end
128
- end
129
-
130
- # Define all the Gem errors for gems that reference them.
131
- module Gem
132
- def self.ruby ; <%= Gem.ruby.inspect %> ; end
133
- def self.dir ; @dir ||= File.dirname(File.expand_path(__FILE__)) ; end
134
- class << self ; alias default_dir dir; alias path dir ; end
135
- class LoadError < ::LoadError; end
136
- class Exception < RuntimeError; end
137
- class CommandLineError < Exception; end
138
- class DependencyError < Exception; end
139
- class DependencyRemovalException < Exception; end
140
- class GemNotInHomeException < Exception ; end
141
- class DocumentError < Exception; end
142
- class EndOfYAMLException < Exception; end
143
- class FilePermissionError < Exception; end
144
- class FormatException < Exception; end
145
- class GemNotFoundException < Exception; end
146
- class InstallError < Exception; end
147
- class InvalidSpecificationException < Exception; end
148
- class OperationNotSupportedError < Exception; end
149
- class RemoteError < Exception; end
150
- class RemoteInstallationCancelled < Exception; end
151
- class RemoteInstallationSkipped < Exception; end
152
- class RemoteSourceException < Exception; end
153
- class VerificationError < Exception; end
154
- class SystemExitException < SystemExit; end
155
- end
3
+ <% load_paths.each do |path| -%>
4
+ $LOAD_PATH.unshift "<%= path %>"
156
5
  <% end -%>
6
+ end
@@ -0,0 +1,51 @@
1
+ module Bundler
2
+ class UI
3
+ def warn(message)
4
+ end
5
+
6
+ def error(message)
7
+ end
8
+
9
+ def info(message)
10
+ end
11
+
12
+ def confirm(message)
13
+ end
14
+
15
+ class Shell < UI
16
+ def initialize(shell)
17
+ @shell = shell
18
+ end
19
+
20
+ def info(msg)
21
+ @shell.say(msg)
22
+ end
23
+
24
+ def confirm(msg)
25
+ @shell.say(msg, :green)
26
+ end
27
+
28
+ def warn(msg)
29
+ @shell.say(msg, :yellow)
30
+ end
31
+
32
+ def error(msg)
33
+ @shell.say(msg, :error)
34
+ end
35
+ end
36
+
37
+ class RGProxy < Gem::SilentUI
38
+ def initialize(ui)
39
+ @ui = ui
40
+ end
41
+
42
+ def say(message)
43
+ if message =~ /native extensions/
44
+ @ui.info " * #{message}"
45
+ else
46
+ @ui.info(message)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,241 @@
1
+ require 'thor/base'
2
+ require 'thor/group'
3
+ require 'thor/actions'
4
+
5
+ # TODO: Update thor to allow for git-style CLI (git bisect run)
6
+ class Thor
7
+ class << self
8
+ # Sets the default task when thor is executed without an explicit task to be called.
9
+ #
10
+ # ==== Parameters
11
+ # meth<Symbol>:: name of the defaut task
12
+ #
13
+ def default_task(meth=nil)
14
+ case meth
15
+ when :none
16
+ @default_task = 'help'
17
+ when nil
18
+ @default_task ||= from_superclass(:default_task, 'help')
19
+ else
20
+ @default_task = meth.to_s
21
+ end
22
+ end
23
+
24
+ # Defines the usage and the description of the next task.
25
+ #
26
+ # ==== Parameters
27
+ # usage<String>
28
+ # description<String>
29
+ #
30
+ def desc(usage, description, options={})
31
+ if options[:for]
32
+ task = find_and_refresh_task(options[:for])
33
+ task.usage = usage if usage
34
+ task.description = description if description
35
+ else
36
+ @usage, @desc = usage, description
37
+ end
38
+ end
39
+
40
+ # Maps an input to a task. If you define:
41
+ #
42
+ # map "-T" => "list"
43
+ #
44
+ # Running:
45
+ #
46
+ # thor -T
47
+ #
48
+ # Will invoke the list task.
49
+ #
50
+ # ==== Parameters
51
+ # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
52
+ #
53
+ def map(mappings=nil)
54
+ @map ||= from_superclass(:map, {})
55
+
56
+ if mappings
57
+ mappings.each do |key, value|
58
+ if key.respond_to?(:each)
59
+ key.each {|subkey| @map[subkey] = value}
60
+ else
61
+ @map[key] = value
62
+ end
63
+ end
64
+ end
65
+
66
+ @map
67
+ end
68
+
69
+ # Declares the options for the next task to be declared.
70
+ #
71
+ # ==== Parameters
72
+ # Hash[Symbol => Object]:: The hash key is the name of the option and the value
73
+ # is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
74
+ # or :required (string). If you give a value, the type of the value is used.
75
+ #
76
+ def method_options(options=nil)
77
+ @method_options ||= {}
78
+ build_options(options, @method_options) if options
79
+ @method_options
80
+ end
81
+
82
+ # Adds an option to the set of method options. If :for is given as option,
83
+ # it allows you to change the options from a previous defined task.
84
+ #
85
+ # def previous_task
86
+ # # magic
87
+ # end
88
+ #
89
+ # method_option :foo => :bar, :for => :previous_task
90
+ #
91
+ # def next_task
92
+ # # magic
93
+ # end
94
+ #
95
+ # ==== Parameters
96
+ # name<Symbol>:: The name of the argument.
97
+ # options<Hash>:: Described below.
98
+ #
99
+ # ==== Options
100
+ # :desc - Description for the argument.
101
+ # :required - If the argument is required or not.
102
+ # :default - Default value for this argument. It cannot be required and have default values.
103
+ # :aliases - Aliases for this option.
104
+ # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
105
+ # :banner - String to show on usage notes.
106
+ #
107
+ def method_option(name, options={})
108
+ scope = if options[:for]
109
+ find_and_refresh_task(options[:for]).options
110
+ else
111
+ method_options
112
+ end
113
+
114
+ build_option(name, options, scope)
115
+ end
116
+
117
+ # Parses the task and options from the given args, instantiate the class
118
+ # and invoke the task. This method is used when the arguments must be parsed
119
+ # from an array. If you are inside Ruby and want to use a Thor class, you
120
+ # can simply initialize it:
121
+ #
122
+ # script = MyScript.new(args, options, config)
123
+ # script.invoke(:task, first_arg, second_arg, third_arg)
124
+ #
125
+ def start(given_args=ARGV, config={})
126
+ super do
127
+ meth = normalize_task_name(given_args.shift)
128
+ task = all_tasks[meth]
129
+
130
+ if task
131
+ args, opts = Thor::Options.split(given_args)
132
+ config.merge!(:task_options => task.options)
133
+ else
134
+ args, opts = given_args, {}
135
+ end
136
+
137
+ task ||= Thor::Task::Dynamic.new(meth)
138
+ trailing = args[Range.new(arguments.size, -1)]
139
+ new(args, opts, config).invoke(task, trailing || [])
140
+ end
141
+ end
142
+
143
+ # Prints help information for the given task.
144
+ #
145
+ # ==== Parameters
146
+ # shell<Thor::Shell>
147
+ # task_name<String>
148
+ #
149
+ def task_help(shell, task_name)
150
+ task = all_tasks[task_name]
151
+ raise UndefinedTaskError, "task '#{task_name}' could not be found in namespace '#{self.namespace}'" unless task
152
+
153
+ shell.say "Usage:"
154
+ shell.say " #{banner(task)}"
155
+ shell.say
156
+ class_options_help(shell, nil => task.options.map { |_, o| o })
157
+ shell.say task.description
158
+ end
159
+
160
+ # Prints help information for this class.
161
+ #
162
+ # ==== Parameters
163
+ # shell<Thor::Shell>
164
+ #
165
+ def help(shell)
166
+ list = printable_tasks
167
+ Thor::Util.thor_classes_in(self).each do |klass|
168
+ list += klass.printable_tasks(false)
169
+ end
170
+ list.sort!{ |a,b| a[0] <=> b[0] }
171
+
172
+ shell.say "Tasks:"
173
+ shell.print_table(list, :ident => 2, :truncate => true)
174
+ shell.say
175
+ class_options_help(shell)
176
+ end
177
+
178
+ # Returns tasks ready to be printed.
179
+ def printable_tasks(all=true)
180
+ (all ? all_tasks : tasks).map do |_, task|
181
+ item = []
182
+ item << banner(task)
183
+ item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
184
+ item
185
+ end
186
+ end
187
+
188
+ protected
189
+
190
+ # The banner for this class. You can customize it if you are invoking the
191
+ # thor class by another ways which is not the Thor::Runner. It receives
192
+ # the task that is going to be invoked and a boolean which indicates if
193
+ # the namespace should be displayed as arguments.
194
+ #
195
+ def banner(task)
196
+ "thor " + task.formatted_usage(self)
197
+ end
198
+
199
+ def baseclass #:nodoc:
200
+ Thor
201
+ end
202
+
203
+ def create_task(meth) #:nodoc:
204
+ if @usage && @desc
205
+ tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
206
+ @usage, @desc, @method_options = nil
207
+ true
208
+ elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing
209
+ true
210
+ else
211
+ puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
212
+ "Call desc if you want this method to be available as task or declare it inside a " <<
213
+ "no_tasks{} block. Invoked from #{caller[1].inspect}."
214
+ false
215
+ end
216
+ end
217
+
218
+ def initialize_added #:nodoc:
219
+ class_options.merge!(method_options)
220
+ @method_options = nil
221
+ end
222
+
223
+ # Receives a task name (can be nil), and try to get a map from it.
224
+ # If a map can't be found use the sent name or the default task.
225
+ #
226
+ def normalize_task_name(meth) #:nodoc:
227
+ mapping = map[meth.to_s]
228
+ meth = mapping || meth || default_task
229
+ meth.to_s.gsub('-','_') # treat foo-bar > foo_bar
230
+ end
231
+ end
232
+
233
+ include Thor::Base
234
+
235
+ map HELP_MAPPINGS => :help
236
+
237
+ desc "help [TASK]", "Describe available tasks or one specific task"
238
+ def help(task=nil)
239
+ task ? self.class.task_help(shell, task) : self.class.help(shell)
240
+ end
241
+ end