bundler-dependency_graph 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c475e34f8059c0ad08d811041f2530b17a30e488
4
+ data.tar.gz: 00e106e8f36fa38b464eea212d1d497e9554ab15
5
+ SHA512:
6
+ metadata.gz: a7a71c073cf97f6ef282c92595db67193d2efb142e22230521a80226b186d84ae1c996fe0967ca87d87153665c0d06d07341a13f64aa20ab4e8193d0880098a3
7
+ data.tar.gz: 1fc4c2df009eb97a59d25d7d312a317053a1b3cf46e29ae79c12679f5bae759a05a447a5d0ed3f057ae1f31c01cc5e2ebd93156417968ad2706e640af95c452b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kerrizor@github.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bundler-dependency_graph.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kerri Miller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Bundler::DependencyGraph
2
+
3
+ A bundler plugin that generates a visual representation of your gem dependencies.
4
+
5
+ ## Installation
6
+
7
+
8
+ $ bundle plugin install bundler-dependency_graph --git "https://github.com/kerrizor/bundler-dependency_graph"
9
+
10
+ ## Usage
11
+
12
+ $ bundle graph
13
+
14
+ ## Development
15
+
16
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
17
+
18
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bundler-dependency_graph. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
23
+
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bundler/dependency_graph"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bundler/dependency_graph/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bundler-dependency_graph"
8
+ spec.version = Bundler::DependencyGraph::VERSION
9
+ spec.authors = ["Kerri Miller", "Whitney-Rose Levis"]
10
+ spec.email = ["kerrizor@kerrizor.com", "whitney@nird.us"]
11
+
12
+ spec.summary = %q{Generate a visual representation of your gem dependencies.}
13
+ spec.description = %q{A bundler plugin that generates a visual representation of your gem dependencies.}
14
+ spec.homepage = "https://github.com/kerrizor/bundler-dependency_graph"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ end
@@ -0,0 +1,3 @@
1
+ require "bundler/dependency_graph/version"
2
+ require "bundler/dependency_graph/graph_builder"
3
+ require "bundler/dependency_graph/graph"
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+ require "set"
3
+ module Bundler
4
+ module DependencyGraph
5
+ class Graph
6
+ GRAPH_NAME = :Gemfile
7
+
8
+ def initialize(env, output_file, show_version = false, show_requirements = false, output_format = "png", without = [])
9
+ @env = env
10
+ @output_file = output_file
11
+ @show_version = show_version
12
+ @show_requirements = show_requirements
13
+ @output_format = output_format
14
+ @without_groups = without.map(&:to_sym)
15
+
16
+ @groups = []
17
+ @relations = Hash.new {|h, k| h[k] = Set.new }
18
+ @node_options = {}
19
+ @edge_options = {}
20
+
21
+ _populate_relations
22
+ end
23
+
24
+ attr_reader :groups, :relations, :node_options, :edge_options, :output_file, :output_format
25
+
26
+ def viz
27
+ GraphVizClient.new(self).run
28
+ end
29
+
30
+ private
31
+
32
+ def _populate_relations
33
+ parent_dependencies = _groups.values.to_set.flatten
34
+ loop do
35
+ break if parent_dependencies.empty?
36
+
37
+ tmp = Set.new
38
+ parent_dependencies.each do |dependency|
39
+ child_dependencies = spec_for_dependency(dependency).runtime_dependencies.to_set
40
+ @relations[dependency.name] += child_dependencies.map(&:name).to_set
41
+ tmp += child_dependencies
42
+
43
+ @node_options[dependency.name] = _make_label(dependency, :node)
44
+ child_dependencies.each do |c_dependency|
45
+ @edge_options["#{dependency.name}_#{c_dependency.name}"] = _make_label(c_dependency, :edge)
46
+ end
47
+ end
48
+ parent_dependencies = tmp
49
+ end
50
+ end
51
+
52
+ def _groups
53
+ relations = Hash.new {|h, k| h[k] = Set.new }
54
+ @env.current_dependencies.each do |dependency|
55
+ dependency.groups.each do |group|
56
+ next if @without_groups.include?(group)
57
+
58
+ relations[group.to_s].add(dependency)
59
+ @relations[group.to_s].add(dependency.name)
60
+
61
+ @node_options[group.to_s] ||= _make_label(group, :node)
62
+ @edge_options["#{group}_#{dependency.name}"] = _make_label(dependency, :edge)
63
+ end
64
+ end
65
+ @groups = relations.keys
66
+ relations
67
+ end
68
+
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#{spec_for_dependency(symbol_or_string_or_dependency).version}" 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"
83
+ end
84
+ else
85
+ raise ArgumentError, "2nd argument is invalid"
86
+ end
87
+ label.nil? ? {} : { :label => label }
88
+ end
89
+
90
+ def spec_for_dependency(dependency)
91
+ @env.requested_specs.find {|s| s.name == dependency.name }
92
+ end
93
+
94
+ class GraphVizClient
95
+ def initialize(graph_instance)
96
+ @graph_name = graph_instance.class::GRAPH_NAME
97
+ @groups = graph_instance.groups
98
+ @relations = graph_instance.relations
99
+ @node_options = graph_instance.node_options
100
+ @edge_options = graph_instance.edge_options
101
+ @output_file = graph_instance.output_file
102
+ @output_format = graph_instance.output_format
103
+ end
104
+
105
+ def g
106
+ @g ||= ::GraphViz.digraph(@graph_name, :concentrate => true, :normalize => true, :nodesep => 0.55) do |g|
107
+ g.edge[:weight] = 2
108
+ g.edge[:fontname] = g.node[:fontname] = "Arial, Helvetica, SansSerif"
109
+ g.edge[:fontsize] = 12
110
+ end
111
+ end
112
+
113
+ def run
114
+ @groups.each do |group|
115
+ g.add_nodes(
116
+ group, {
117
+ :style => "filled",
118
+ :fillcolor => "#B9B9D5",
119
+ :shape => "box3d",
120
+ :fontsize => 16
121
+ }.merge(@node_options[group])
122
+ )
123
+ end
124
+
125
+ @relations.each do |parent, children|
126
+ children.each do |child|
127
+ if @groups.include?(parent)
128
+ g.add_nodes(child, { :style => "filled", :fillcolor => "#B9B9D5" }.merge(@node_options[child]))
129
+ g.add_edges(parent, child, { :constraint => false }.merge(@edge_options["#{parent}_#{child}"]))
130
+ else
131
+ g.add_nodes(child, @node_options[child])
132
+ g.add_edges(parent, child, @edge_options["#{parent}_#{child}"])
133
+ end
134
+ end
135
+ end
136
+
137
+ if @output_format.to_s == "debug"
138
+ $stdout.puts g.output :none => String
139
+ Bundler.ui.info "debugging bundle viz..."
140
+ else
141
+ begin
142
+ g.output @output_format.to_sym => "#{@output_file}.#{@output_format}"
143
+ Bundler.ui.info "#{@output_file}.#{@output_format}"
144
+ rescue ArgumentError => e
145
+ $stderr.puts "Unsupported output format. See Ruby-Graphviz/lib/graphviz/constants.rb"
146
+ raise e
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,38 @@
1
+ module Bundler
2
+ module DependencyGraph
3
+ class GraphBuilder
4
+ Bundler::Plugin::API.command "graph", self
5
+
6
+ def exec(command, args)
7
+ puts "Currently unimplented; use `bundle viz` to generate your graphs for now."
8
+
9
+ require "graphviz"
10
+
11
+ # Temporarily assign default values to incoming args. In Bundler, these
12
+ # are handled by Thor, but we're not entirely sure how the
13
+ # Bundler::Plugin::API passes them (or doesn't) to plugins
14
+
15
+ options = {}
16
+ options[:file] = "gem_graph"
17
+ options[:format] = "png"
18
+ options[:requirements] = false
19
+ options[:version] = false
20
+ options[:without] = []
21
+
22
+ options[:without] = options[:without].join(":").tr(" ", ":").split(":")
23
+ output_file = File.expand_path(options[:file])
24
+
25
+ graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format], options[:without])
26
+ graph.viz
27
+ rescue LoadError => e
28
+ Bundler.ui.error e.inspect
29
+ Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
30
+ Bundler.ui.warn "`gem install ruby-graphviz`"
31
+ rescue StandardError => e
32
+ raise unless e.message =~ /GraphViz not installed or dot not in PATH/
33
+ Bundler.ui.error e.message
34
+ Bundler.ui.warn "Please install GraphViz. On a Mac with Homebrew, you can run `brew install graphviz`."
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ module DependencyGraph
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "bundler/dependency_graph"
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-dependency_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kerri Miller
8
+ - Whitney-Rose Levis
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-02-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.14'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.14'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ description: A bundler plugin that generates a visual representation of your gem dependencies.
57
+ email:
58
+ - kerrizor@kerrizor.com
59
+ - whitney@nird.us
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - bundler-dependency_graph.gemspec
74
+ - lib/bundler/dependency_graph.rb
75
+ - lib/bundler/dependency_graph/graph.rb
76
+ - lib/bundler/dependency_graph/graph_builder.rb
77
+ - lib/bundler/dependency_graph/version.rb
78
+ - plugins.rb
79
+ homepage: https://github.com/kerrizor/bundler-dependency_graph
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.10
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Generate a visual representation of your gem dependencies.
103
+ test_files: []