bundler 1.1.rc.3 → 1.1.rc.5

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.

@@ -1,3 +1,20 @@
1
+ ## 1.1.rc.5 (Dec 14, 2011)
2
+
3
+ Bugfixes:
4
+
5
+ - Fix ASCII encoding errors with gem (rerelease with ruby 1.8)
6
+
7
+ ## 1.1.rc.4 (Dec 14, 2011)
8
+
9
+ Features:
10
+
11
+ - `bundle viz` has the option to output a DOT file instead of a PNG (@hirochachacha, #683)
12
+
13
+ Bugfixes:
14
+
15
+ - Ensure binstubs generated when using --standalone point to the standalonde bundle (@cowboyd, #1588)
16
+ - fix `bundle viz` (@hirochachacha, #1586)
17
+
1
18
  ## 1.1.rc.3 (Dec 8, 2011)
2
19
 
3
20
  Bugfixes:
@@ -507,16 +507,17 @@ module Bundler
507
507
  Viz requires the ruby-graphviz gem (and its dependencies).
508
508
  The associated gems must also be installed via 'bundle install'.
509
509
  D
510
- method_option :file, :type => :string, :default => 'gem_graph.png', :aliases => '-f', :banner => "The name to use for the generated png file."
510
+ method_option :file, :type => :string, :default => 'gem_graph', :aliases => '-f', :banner => "The name to use for the generated file. see format option"
511
511
  method_option :version, :type => :boolean, :default => false, :aliases => '-v', :banner => "Set to show each gem version."
512
512
  method_option :requirements, :type => :boolean, :default => false, :aliases => '-r', :banner => "Set to show the version of each required dependency."
513
+ method_option :format, :type => :string, :default => "png", :aliases => '-F', :banner => "This is output format option. Supported format is png, jpg, svg, dot ..."
513
514
  def viz
514
515
  output_file = File.expand_path(options[:file])
515
- graph = Graph.new( Bundler.load )
516
+ output_format = options[:format]
517
+ graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format])
516
518
 
517
519
  begin
518
- graph.viz(output_file, options[:version], options[:requirements])
519
- Bundler.ui.info output_file
520
+ graph.viz
520
521
  rescue LoadError => e
521
522
  Bundler.ui.error e.inspect
522
523
  Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
@@ -1,130 +1,148 @@
1
+ require 'set'
1
2
  module Bundler
2
3
  class Graph
4
+ GRAPH_NAME = :Gemfile
3
5
 
4
- USER_OPTIONS = {:style => 'filled', :fillcolor => '#B9B9D5'}.freeze
6
+ def initialize(env, output_file, show_version = false, show_requirements = false, output_format = "png")
7
+ @env = env
8
+ @output_file = output_file
9
+ @show_version = show_version
10
+ @show_requirements = show_requirements
11
+ @output_format = output_format
5
12
 
6
- def initialize(env)
7
- @env = env
8
- end
9
-
10
- def nodes
11
- populate
12
- @nodes
13
- end
13
+ @groups = []
14
+ @relations = Hash.new {|h, k| h[k] = Set.new}
15
+ @node_options = {}
16
+ @edge_options = {}
14
17
 
15
- def groups
16
- populate
17
- @groups
18
+ _populate_relations
18
19
  end
19
20
 
20
- def viz(output_file, show_gem_versions = false, show_dependency_requirements = false)
21
- require 'graphviz'
22
- populate
21
+ attr_reader :groups, :relations, :node_options, :edge_options, :output_file, :output_format
23
22
 
24
- graph_viz = GraphViz::new('Gemfile', {:concentrate => true, :normalize => true, :nodesep => 0.55})
25
- graph_viz.edge[:fontname] = graph_viz.node[:fontname] = 'Arial, Helvetica, SansSerif'
26
- graph_viz.edge[:fontsize] = 12
27
-
28
- viz_nodes = {}
23
+ def viz
24
+ GraphVizClient.new(self).run
25
+ end
29
26
 
30
- # populate all of the nodes
31
- nodes.each do |name, node|
32
- label = name.dup
33
- label << "\n#{node.version}" if show_gem_versions
34
- options = { :label => label }
35
- options.merge!( USER_OPTIONS ) if node.is_user
36
- viz_nodes[name] = graph_viz.add_node( name, options )
37
- end
27
+ private
38
28
 
39
- group_nodes = {}
40
- @groups.each do |name, dependencies|
41
- group_nodes[name] = graph_viz.add_node(name.to_s, { :shape => 'box3d', :fontsize => 16 }.merge(USER_OPTIONS))
42
- dependencies.each do |dependency|
43
- options = { :weight => 2 }
44
- if show_dependency_requirements && (dependency.requirement.to_s != ">= 0")
45
- options[:label] = dependency.requirement.to_s
29
+ def _populate_relations
30
+ relations = Hash.new {|h, k| h[k] = Set.new}
31
+ parent_dependencies = _groups.values.to_set.flatten
32
+ while true
33
+ if parent_dependencies.empty?
34
+ break
35
+ else
36
+ tmp = Set.new
37
+ parent_dependencies.each do |dependency|
38
+ child_dependencies = dependency.to_spec.runtime_dependencies.to_set
39
+ relations[dependency.name] += child_dependencies.to_set
40
+ @relations[dependency.name] += child_dependencies.map(&:name).to_set
41
+ tmp += child_dependencies
42
+
43
+ @node_options[dependency.name] = {:label => _make_label(dependency, :node)}
44
+ child_dependencies.each do |c_dependency|
45
+ @edge_options["#{dependency.name}_#{c_dependency.name}"] = {:label => _make_label(c_dependency, :edge)}
46
+ end
46
47
  end
47
- graph_viz.add_edge( group_nodes[name], viz_nodes[dependency.name], options )
48
+ parent_dependencies = tmp
48
49
  end
49
50
  end
51
+ @relations
52
+ end
50
53
 
51
- @groups.keys.select { |group| group != :default }.each do |group|
52
- graph_viz.add_edge( group_nodes[group], group_nodes[:default], { :weight => 2 } )
53
- end
54
-
55
- viz_nodes.each do |name, node|
56
- nodes[name].dependencies.each do |dependency|
57
- options = { }
58
- if nodes[dependency.name].is_user
59
- options[:constraint] = false
60
- end
61
- if show_dependency_requirements && (dependency.requirement.to_s != ">= 0")
62
- options[:label] = dependency.requirement.to_s
63
- end
54
+ def _groups
55
+ relations = Hash.new {|h, k| h[k] = Set.new}
56
+ @env.current_dependencies.each do |dependency|
57
+ dependency.groups.each do |group|
58
+ relations[group.to_s].add(dependency)
59
+ @relations[group.to_s].add(dependency.name)
64
60
 
65
- graph_viz.add_edge( node, viz_nodes[dependency.name], options )
61
+ @node_options[group.to_s] ||= {:label => _make_label(group, :node)}
62
+ @edge_options["#{group}_#{dependency.name}"] = {:label => _make_label(dependency, :edge)}
66
63
  end
67
64
  end
68
-
69
- graph_viz.output( :png => output_file )
65
+ @groups = relations.keys
66
+ relations
70
67
  end
71
68
 
72
- private
73
-
74
- def populate
75
- return if @populated
76
-
77
- # hash of name => GraphNode
78
- @nodes = {}
79
- @groups = {}
80
-
81
- # Populate @nodes
82
- @env.specs.each { |spec| @nodes[spec.name] = GraphNode.new(spec.name, spec.version) }
83
-
84
- # For gems in Gemfile, add details
85
- @env.current_dependencies.each do |dependency|
86
- next unless node = @nodes[dependency.name]
87
- node.is_user = true
88
-
89
- dependency.groups.each do |group|
90
- if @groups.has_key? group
91
- group = @groups[group]
92
- else
93
- group = @groups[group] = []
94
- end
95
- group << dependency
69
+ def _make_label(symbol_or_string_or_dependency, element_type)
70
+ case element_type.to_sym
71
+ when :node
72
+ if symbol_or_string_or_dependency.is_a?(Gem::Dependency)
73
+ label = symbol_or_string_or_dependency.name.dup
74
+ label << "\n#{symbol_or_string_or_dependency.to_spec.version.to_s}" if @show_version
75
+ else
76
+ label = symbol_or_string_or_dependency.to_s
77
+ end
78
+ when :edge
79
+ label = nil
80
+ if symbol_or_string_or_dependency.respond_to?(:requirements_list) && @show_requirements
81
+ tmp = symbol_or_string_or_dependency.requirements_list.join(", ")
82
+ label = tmp if tmp != ">= 0"
96
83
  end
84
+ else
85
+ raise ArgumentError, "2nd argument is invalid"
97
86
  end
87
+ label
88
+ end
98
89
 
99
- # walk though a final time and add edges
100
- @env.specs.each do |spec|
90
+ class GraphVizClient
91
+ def initialize(graph_instance)
92
+ @graph_name = graph_instance.class::GRAPH_NAME
93
+ @groups = graph_instance.groups
94
+ @relations = graph_instance.relations
95
+ @node_options = graph_instance.node_options
96
+ @edge_options = graph_instance.edge_options
97
+ @output_file = graph_instance.output_file
98
+ @output_format = graph_instance.output_format
99
+ end
101
100
 
102
- from = @nodes[spec.name]
103
- spec.runtime_dependencies.each do |dependency|
104
- from.dependencies << dependency
101
+ def g
102
+ require 'graphviz'
103
+ @g ||= ::GraphViz.digraph(@graph_name, {:concentrate => true, :normalize => true, :nodesep => 0.55}) do |g|
104
+ g.edge[:weight] = 2
105
+ g.edge[:fontname] = g.node[:fontname] = 'Arial, Helvetica, SansSerif'
106
+ g.edge[:fontsize] = 12
105
107
  end
106
-
107
108
  end
108
109
 
109
- @nodes.freeze
110
- @groups.freeze
111
- @populated = true
112
- end
113
-
114
- end
110
+ def run
111
+ @groups.each do |group|
112
+ g.add_node(
113
+ group,
114
+ {:style => 'filled',
115
+ :fillcolor => '#B9B9D5',
116
+ :shape => "box3d",
117
+ :fontsize => 16}.merge(@node_options[group])
118
+ )
119
+ end
115
120
 
116
- # Add version info
117
- class GraphNode
121
+ @relations.each do |parent, children|
122
+ children.each do |child|
123
+ if @groups.include?(parent)
124
+ g.add_node(child, {:style => 'filled', :fillcolor => '#B9B9D5'}.merge(@node_options[child]))
125
+ g.add_edge(parent, child, {:constraint => false}.merge(@edge_options["#{parent}_#{child}"]))
126
+ else
127
+ g.add_node(child, @node_options[child])
128
+ g.add_edge(parent, child, @edge_options["#{parent}_#{child}"])
129
+ end
130
+ end
131
+ end
118
132
 
119
- def initialize(name, version)
120
- @name = name
121
- @version = version
122
- @is_user = false
123
- @dependencies = []
133
+ if @output_format.to_s == "debug"
134
+ $stdout.puts g.output :none => String
135
+ Bundler.ui.info "debugging bundle viz..."
136
+ else
137
+ begin
138
+ g.output @output_format.to_sym => "#{@output_file}.#{@output_format}"
139
+ Bundler.ui.info "#{@output_file}.#{@output_format}"
140
+ rescue ArgumentError => e
141
+ $stderr.puts "Unsupported output format. See Ruby-Graphviz/lib/graphviz/constants.rb"
142
+ raise e
143
+ end
144
+ end
145
+ end
124
146
  end
125
-
126
- attr_reader :name, :dependencies, :version
127
- attr_accessor :is_user
128
-
129
147
  end
130
148
  end
@@ -53,7 +53,7 @@ module Bundler
53
53
  # the gem.
54
54
  Installer.post_install_messages = {}
55
55
  specs.each do |spec|
56
- install_gem_from_spec(spec)
56
+ install_gem_from_spec(spec, options[:standalone])
57
57
  end
58
58
 
59
59
  lock
@@ -62,7 +62,7 @@ module Bundler
62
62
 
63
63
  private
64
64
 
65
- def install_gem_from_spec(spec)
65
+ def install_gem_from_spec(spec, standalone = false)
66
66
  # Download the gem to get the spec, because some specs that are returned
67
67
  # by rubygems.org are broken and wrong.
68
68
  Bundler::Fetcher.fetch(spec) if spec.source.is_a?(Bundler::Source::Rubygems)
@@ -76,7 +76,10 @@ module Bundler
76
76
 
77
77
  # newline comes after installing, some gems say "with native extensions"
78
78
  Bundler.ui.info ""
79
- generate_bundler_executable_stubs(spec) if Bundler.settings[:bin]
79
+ if Bundler.settings[:bin]
80
+ standalone ? generate_standalone_bundler_executable_stubs(spec) : generate_bundler_executable_stubs(spec)
81
+ end
82
+
80
83
  FileUtils.rm_rf(Bundler.tmp)
81
84
  rescue Exception => e
82
85
  # install hook failed
@@ -105,6 +108,21 @@ module Bundler
105
108
  end
106
109
  end
107
110
 
111
+ def generate_standalone_bundler_executable_stubs(spec)
112
+ bin_path = Bundler.bin_path
113
+ template = File.read(File.expand_path('../templates/Executable.standalone', __FILE__))
114
+ ruby_command = Thor::Util.ruby_command
115
+
116
+ spec.executables.each do |executable|
117
+ next if executable == "bundle"
118
+ standalone_path = Pathname(Bundler.settings[:path]).expand_path.relative_path_from(bin_path)
119
+ executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
120
+ File.open "#{bin_path}/#{executable}", 'w', 0755 do |f|
121
+ f.puts ERB.new(template, nil, '-').result(binding)
122
+ end
123
+ end
124
+ end
125
+
108
126
  def generate_standalone(groups)
109
127
  standalone_path = Bundler.settings[:path]
110
128
  bundler_path = File.join(standalone_path, "bundler")
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %>
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application '<%= executable %>' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ $:.unshift File.expand_path '../<%= standalone_path %>', __FILE__
10
+
11
+ require 'bundler/setup'
12
+ load File.expand_path '../<%= executable_path %>', __FILE__
@@ -2,5 +2,5 @@ module Bundler
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.1.rc.3" unless defined?(::Bundler::VERSION)
5
+ VERSION = "1.1.rc.5" unless defined?(::Bundler::VERSION)
6
6
  end
@@ -235,4 +235,26 @@ describe "bundle install --standalone" do
235
235
  end
236
236
  end
237
237
  end
238
+
239
+ describe "with --binstubs" do
240
+ before do
241
+ install_gemfile <<-G, :standalone => true, :binstubs => true
242
+ source "file://#{gem_repo1}"
243
+ gem "rails"
244
+ G
245
+ end
246
+
247
+ it "creates stubs that use the standalone load path" do
248
+ Dir.chdir(bundled_app) do
249
+ `bin/rails -v`.chomp.should eql "2.3.2"
250
+ end
251
+ end
252
+
253
+ it "creates stubs that can be executed from anywhere" do
254
+ require 'tmpdir'
255
+ Dir.chdir(Dir.tmpdir) do
256
+ `#{bundled_app}/bin/rails -v`.chomp.should eql "2.3.2"
257
+ end
258
+ end
259
+ end
238
260
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424251
4
+ hash: 15424247
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - rc
10
- - 3
11
- version: 1.1.rc.3
10
+ - 5
11
+ version: 1.1.rc.5
12
12
  platform: ruby
13
13
  authors:
14
14
  - "Andr\xC3\xA9 Arko"
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2011-12-08 00:00:00 -08:00
22
+ date: 2011-12-14 00:00:00 -05:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -104,6 +104,7 @@ files:
104
104
  - lib/bundler/source.rb
105
105
  - lib/bundler/spec_set.rb
106
106
  - lib/bundler/templates/Executable
107
+ - lib/bundler/templates/Executable.standalone
107
108
  - lib/bundler/templates/Gemfile
108
109
  - lib/bundler/templates/newgem/Gemfile.tt
109
110
  - lib/bundler/templates/newgem/LICENSE.tt