pocky 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pocky.rb +1 -0
- data/lib/pocky/package.rb +28 -15
- data/lib/pocky/packwerk.rb +41 -103
- data/lib/pocky/packwerk_loader.rb +81 -0
- data/lib/pocky/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d72c460dac22e64ff793edb2ed726f95d9366d
|
4
|
+
data.tar.gz: 6bee607df4202ab4b3006a75b31ba67160ecf6cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 778722784ba28b7d8943ffb13342faa81c6937f0a4931f854ffe0656653eca6bcbcf79f488c4224271e488c69842cbaf230d8e5a122c63e739448ffe8c4cc095
|
7
|
+
data.tar.gz: f61dc0bf0b1490d2eb4b43b495cc3de366d60c672a7925b4451cb610654ba54ff77d8f41938ebda5f7691780b96091cda427b5ce7023a19defaa2d3cd3920b9c
|
data/lib/pocky.rb
CHANGED
data/lib/pocky/package.rb
CHANGED
@@ -4,30 +4,43 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module Pocky
|
6
6
|
class Package
|
7
|
-
|
7
|
+
DEPENDENCIES_FILENAME = 'package.yml'
|
8
|
+
DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
|
8
9
|
|
9
|
-
|
10
|
+
attr_reader :name, :dependencies, :enforce_privacy, :primary
|
11
|
+
|
12
|
+
def initialize(name:, path:, primary:)
|
10
13
|
@name = name
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
14
|
+
@path = path
|
15
|
+
@primary = primary
|
16
|
+
@dependencies = dependencies_yml['dependencies'] || []
|
17
|
+
@enforce_privacy = dependencies_yml['enforce_privacy'] || false
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
@deprecated_references
|
20
|
+
def deprecated_references
|
21
|
+
@deprecated_references ||= load_yml(deprecated_references_filename)
|
19
22
|
end
|
20
23
|
|
21
24
|
private
|
22
25
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
{}
|
29
|
-
end
|
26
|
+
def load_yml(filename)
|
27
|
+
if File.file?(filename)
|
28
|
+
YAML.load_file(filename) || {}
|
29
|
+
else
|
30
|
+
{}
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
34
|
+
def dependencies_yml
|
35
|
+
@dependencies_yml ||= load_yml(dependecies_filename)
|
36
|
+
end
|
37
|
+
|
38
|
+
def dependecies_filename
|
39
|
+
File.join(@path, DEPENDENCIES_FILENAME)
|
40
|
+
end
|
41
|
+
|
42
|
+
def deprecated_references_filename
|
43
|
+
File.join(@path, DEPRECATED_REFERENCES_FILENAME)
|
44
|
+
end
|
32
45
|
end
|
33
46
|
end
|
data/lib/pocky/packwerk.rb
CHANGED
@@ -5,8 +5,6 @@ require 'ruby-graphviz'
|
|
5
5
|
|
6
6
|
module Pocky
|
7
7
|
class Packwerk
|
8
|
-
DEPENDENCIES_FILENAME = 'package.yml'
|
9
|
-
DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
|
10
8
|
MAX_EDGE_WIDTH = 5
|
11
9
|
|
12
10
|
def self.generate(params = {})
|
@@ -35,7 +33,6 @@ module Pocky
|
|
35
33
|
@dpi = dpi.to_i
|
36
34
|
@secondary_package_color = secondary_package_color
|
37
35
|
|
38
|
-
@packages = {}
|
39
36
|
@nodes = {}
|
40
37
|
|
41
38
|
@node_options = {
|
@@ -59,14 +56,17 @@ module Pocky
|
|
59
56
|
end
|
60
57
|
|
61
58
|
def generate
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
build_directed_graph
|
59
|
+
@graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
|
60
|
+
draw_packages
|
61
|
+
@graph.output(png: @filename)
|
66
62
|
end
|
67
63
|
|
68
64
|
private
|
69
65
|
|
66
|
+
def packages
|
67
|
+
@packages ||= PackwerkLoader.load(@root_path, @package_paths)
|
68
|
+
end
|
69
|
+
|
70
70
|
def node_overrides(file_size)
|
71
71
|
if file_size < 10
|
72
72
|
{ fontsize: 26 }
|
@@ -81,6 +81,20 @@ module Pocky
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
def draw_packages
|
85
|
+
packages.each do |_name, package|
|
86
|
+
@nodes[package.name] ||= draw_node(package)
|
87
|
+
|
88
|
+
package.dependencies.each do |dependency|
|
89
|
+
draw_dependency(package, dependency)
|
90
|
+
end
|
91
|
+
|
92
|
+
package.deprecated_references.each do |provider_name, invocations|
|
93
|
+
draw_dependency(package, provider_name, invocations)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
84
98
|
def draw_node(package)
|
85
99
|
package_name = package_name_for_dependency(package.name)
|
86
100
|
path = package.name == '.' ? @root_path : @root_path.join(package.name)
|
@@ -92,45 +106,34 @@ module Pocky
|
|
92
106
|
label: node_label
|
93
107
|
)
|
94
108
|
|
95
|
-
if @package_paths.present? &&
|
96
|
-
node_styles.merge!(
|
109
|
+
if @package_paths.present? && !package.primary
|
110
|
+
node_styles.merge!(
|
111
|
+
fillcolor: @secondary_package_color,
|
112
|
+
color: @secondary_package_color
|
113
|
+
)
|
97
114
|
end
|
98
115
|
|
99
116
|
@graph.add_nodes(package_name, **node_styles)
|
100
117
|
end
|
101
118
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
def draw_packages
|
109
|
-
@packages.each do |_name, package|
|
110
|
-
@nodes[package.name] ||= draw_node(package)
|
119
|
+
def draw_dependency(package, dependency, invocations = nil)
|
120
|
+
# Do not draw dependencies of secondary packages (depencies of primary packages)
|
121
|
+
# when visualizing partial system
|
122
|
+
return if !package.primary && !packages[dependency]
|
111
123
|
|
112
|
-
|
113
|
-
@nodes[dependency] ||= draw_node(@packages[dependency])
|
124
|
+
@nodes[dependency] ||= draw_node(packages[dependency])
|
114
125
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
126
|
+
edge_options = invocations ?
|
127
|
+
@deprecated_references_edge_options.merge(
|
128
|
+
penwidth: edge_width(invocations.length),
|
129
|
+
) :
|
130
|
+
@dependency_edge_options
|
121
131
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@nodes[provider_name],
|
128
|
-
**@deprecated_references_edge_options.merge(
|
129
|
-
penwidth: edge_width(invocations.length),
|
130
|
-
),
|
131
|
-
)
|
132
|
-
end
|
133
|
-
end
|
132
|
+
@graph.add_edges(
|
133
|
+
@nodes[package.name],
|
134
|
+
@nodes[dependency],
|
135
|
+
**edge_options
|
136
|
+
)
|
134
137
|
end
|
135
138
|
|
136
139
|
def edge_width(count)
|
@@ -140,71 +143,6 @@ module Pocky
|
|
140
143
|
].min
|
141
144
|
end
|
142
145
|
|
143
|
-
def deprecated_references_files
|
144
|
-
@deprecated_references_files ||= begin
|
145
|
-
return Dir[@root_path.join('**', DEPRECATED_REFERENCES_FILENAME).to_s] unless @package_paths
|
146
|
-
|
147
|
-
@package_paths.flat_map do |path|
|
148
|
-
Dir[@root_path.join(path, '**', DEPRECATED_REFERENCES_FILENAME).to_s]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def dependencies_files
|
154
|
-
@dependencies_files ||= begin
|
155
|
-
return Dir[@root_path.join('**', DEPENDENCIES_FILENAME).to_s] unless @package_paths
|
156
|
-
|
157
|
-
@package_paths.flat_map do |path|
|
158
|
-
Dir[@root_path.join(path, '**', DEPENDENCIES_FILENAME).to_s]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def load_dependencies
|
164
|
-
return if dependencies_files.empty?
|
165
|
-
|
166
|
-
dependencies_files.each do |filename|
|
167
|
-
package_name = parse_package_name(filename)
|
168
|
-
@packages[package_name] ||= Pocky::Package.new(name: package_name, filename: filename)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def load_deprecated_references
|
173
|
-
return if deprecated_references_files.empty?
|
174
|
-
|
175
|
-
deprecated_references_files.each do |filename|
|
176
|
-
package_name = parse_package_name(filename)
|
177
|
-
@packages[package_name] ||= Pocky::Package.new(name: package_name)
|
178
|
-
@packages[package_name].add_deprecated_references(filename)
|
179
|
-
|
180
|
-
# Walk the references to create referenced packages
|
181
|
-
@packages[package_name].deprecated_references.each do |provider_name, _violations|
|
182
|
-
@packages[provider_name] ||= Pocky::Package.new(name: provider_name)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
# This must be run as the very last step of packages graph building because these won't have
|
188
|
-
# dependency filename reference.
|
189
|
-
def load_uninitialized_dependencies
|
190
|
-
return if dependencies_files.empty?
|
191
|
-
|
192
|
-
# When analyzing partial system, some packages may not be initialized as part of
|
193
|
-
# dependencies/deprecated references walk. So we take care of initializing them here
|
194
|
-
# before drawing.
|
195
|
-
dependencies_files.each do |filename|
|
196
|
-
package_name = parse_package_name(filename)
|
197
|
-
@packages[package_name].dependencies.each do |dependency|
|
198
|
-
@packages[dependency] ||= Pocky::Package.new(name: dependency)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def parse_package_name(filename)
|
204
|
-
name = File.dirname(filename).gsub(@root_path.to_s, '')
|
205
|
-
name == '' ? '.' : name.gsub(/^\//, '')
|
206
|
-
end
|
207
|
-
|
208
146
|
def package_name_for_dependency(name)
|
209
147
|
name == '.' ? @default_package : name
|
210
148
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pocky
|
4
|
+
class PackwerkLoader
|
5
|
+
def self.load(root_path, package_paths)
|
6
|
+
new(root_path, package_paths).load
|
7
|
+
end
|
8
|
+
|
9
|
+
private_class_method :new
|
10
|
+
def initialize(root_path, package_paths)
|
11
|
+
@root_path = root_path
|
12
|
+
@package_paths = package_paths
|
13
|
+
@packages = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def load
|
17
|
+
load_primary_packages
|
18
|
+
load_secondary_packages
|
19
|
+
|
20
|
+
@packages
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def deprecated_references_files
|
26
|
+
@deprecated_references_files ||= begin
|
27
|
+
return Dir[@root_path.join('**', Pocky::Package::DEPRECATED_REFERENCES_FILENAME).to_s] unless @package_paths
|
28
|
+
|
29
|
+
@package_paths.flat_map do |path|
|
30
|
+
Dir[@root_path.join(path, '**', Pocky::Package::DEPRECATED_REFERENCES_FILENAME).to_s]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def dependencies_files
|
36
|
+
@dependencies_files ||= begin
|
37
|
+
return Dir[@root_path.join('**', Pocky::Package::DEPENDENCIES_FILENAME).to_s] unless @package_paths
|
38
|
+
|
39
|
+
@package_paths.flat_map do |path|
|
40
|
+
Dir[@root_path.join(path, '**', Pocky::Package::DEPENDENCIES_FILENAME).to_s]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def init_package(package_name, primary)
|
46
|
+
Pocky::Package.new(
|
47
|
+
name: package_name,
|
48
|
+
path: @root_path.join(package_name).to_s,
|
49
|
+
primary: primary
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_primary_packages
|
54
|
+
filenames = dependencies_files + deprecated_references_files
|
55
|
+
primary_package_names = filenames.map { |filename| parse_package_name(filename) }.uniq
|
56
|
+
primary_package_names.each do |name|
|
57
|
+
@packages[name] ||= init_package(name, true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_secondary_packages
|
62
|
+
secondary_packages = {}
|
63
|
+
@packages.each do |_, package|
|
64
|
+
package.dependencies.each do |dependency|
|
65
|
+
secondary_packages[dependency] ||= init_package(dependency, false) unless @packages[dependency]
|
66
|
+
end
|
67
|
+
|
68
|
+
package.deprecated_references.each do |reference, _violations|
|
69
|
+
secondary_packages[reference] ||= init_package(reference, false) unless @packages[reference]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
@packages.merge!(secondary_packages)
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_package_name(filename)
|
77
|
+
name = File.dirname(filename).gsub(@root_path.to_s, '')
|
78
|
+
name == '' ? '.' : name.gsub(/^\//, '')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/pocky/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pocky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Quan Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-graphviz
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/pocky/Rakefile
|
45
45
|
- lib/pocky/package.rb
|
46
46
|
- lib/pocky/packwerk.rb
|
47
|
+
- lib/pocky/packwerk_loader.rb
|
47
48
|
- lib/pocky/railtie.rb
|
48
49
|
- lib/pocky/ruby_file_size.rb
|
49
50
|
- lib/pocky/tasks/generate.rake
|