power_stencil 0.9.2 → 0.9.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26cb59d7fdc8d324704956de580c938d9fb22f80
4
- data.tar.gz: 0ad6c0e26e6e47bbd7d37959f09e389056bd9094
3
+ metadata.gz: c36f08f7b3ad9a916e27a18e755af6794084b97f
4
+ data.tar.gz: 82104cf2bda5b15f57020b57ccf66b1e95ee241c
5
5
  SHA512:
6
- metadata.gz: 7391eacdb19ef569ba482275c91f0d6cb048ad58a77de8f177fa6068577f1ba72ac83db11e56fa61da065de093141f50c62755cbe74104fc6e471e12fcd47512
7
- data.tar.gz: 228e549dbc115c384b01e8b7d1f24398d3c833e10754a202d6e72d491e00d12d01b8c442fe897b827217d32015efdd9b41aa60fad9f7231eab256c3988c7171e
6
+ metadata.gz: 6d1db8dd8989c9299eea8fe869e527f7c86b93db49353962ecf2620a34614fb143a39b02e12480dd02929c57c5adce19ec53b35754e327e79c9620bff0d1708f
7
+ data.tar.gz: 8e1377704873ca6d8a8eb69c4ba7e41f3e2a9cb0af77b3c7d06ea5bb5fc3174b72dc3df81140dcbd4cb0c286b21bac3ebc7e15fff4ff44d82e4e08acc5925e31
@@ -7,5 +7,6 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.idea/
10
+ Gemfile.lock
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -2,7 +2,7 @@
2
2
  <%= plugin_title_name %>
3
3
  <%= '=' * plugin_title_name.size %>
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
5
+ [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
6
6
 
7
7
  [PowerStencil] is the Swiss-army knife templating workflow for developers and ops.
8
8
 
@@ -32,3 +32,6 @@
32
32
  :templates:
33
33
  - etc/templates
34
34
 
35
+ # Plugin dependencies to other plugins. Use the plugin name and NOT the plugin
36
+ # gem name (in the case of a gem plugin). Declare as well dependencies to local plugins.
37
+ :dependencies: []
@@ -7,5 +7,6 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.idea/
10
+ Gemfile.lock
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -2,7 +2,7 @@
2
2
  <%= plugin_title_name %>
3
3
  <%= '=' * plugin_title_name.size %>
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
5
+ [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
6
6
 
7
7
  [PowerStencil] is the Swiss-army knife templating workflow for developers and ops.
8
8
 
@@ -32,3 +32,6 @@
32
32
  :templates:
33
33
  - etc/templates
34
34
 
35
+ # Plugin dependencies to other plugins. Use the plugin name and NOT the plugin
36
+ # gem name (in the case of a gem plugin). Declare as well dependencies to local plugins.
37
+ :dependencies: []
@@ -7,6 +7,7 @@
7
7
 
8
8
  # Project plugins gems
9
9
  # List of plugins, provided as real Ruby gems (outside of this project), that you want to use in this project.
10
+ # Here declare the gem name, not the plugin name.
10
11
  # :project_plugins: []
11
12
 
12
13
  # Graphviz configuration
@@ -50,7 +50,7 @@ module PowerStencil
50
50
  private
51
51
 
52
52
  def load_plugins_entities_definition
53
- project.plugins.each do |_, plugin|
53
+ project.plugins_sorted_by_dependency.each do |plugin|
54
54
  plugin.require_plugin_entity_definitions
55
55
  end
56
56
  end
@@ -70,7 +70,6 @@ module PowerStencil
70
70
  load_capabilities
71
71
  load_plugin_specific_config
72
72
  load_yaml_command_definition
73
- require_entry_point
74
73
  end
75
74
 
76
75
  end
@@ -13,6 +13,10 @@ module PowerStencil
13
13
  @capabilities ||= CAPABILITIES.dup.zip([false] * CAPABILITIES.size).to_h
14
14
  end
15
15
 
16
+ def dependencies
17
+ plugin_definition[:dependencies]
18
+ end
19
+
16
20
  private
17
21
 
18
22
  def load_capabilities
@@ -7,12 +7,6 @@ module PowerStencil
7
7
 
8
8
  include PowerStencil::Utils::SecureRequire
9
9
 
10
- private
11
-
12
- def module_short_name
13
- name.split(/[-_]+/).map(&:capitalize).join.to_sym
14
- end
15
-
16
10
  def require_entry_point
17
11
  @entry_point_path = File.join plugin_path, 'lib', "#{name.underscore}.rb"
18
12
  logger.debug "Plugin '#{name}' entry point: '#{entry_point_path}'"
@@ -27,6 +21,12 @@ module PowerStencil
27
21
  end
28
22
  end
29
23
 
24
+ private
25
+
26
+ def module_short_name
27
+ name.split(/[-_]+/).map(&:capitalize).join.to_sym
28
+ end
29
+
30
30
  def setup_version
31
31
  @version = PowerStencil::Utils::SemanticVersion.new plugin_module::VERSION
32
32
  capabilities[:version] = true
@@ -1,3 +1,5 @@
1
+ require 'power_stencil/utils/dependency_solver'
2
+
1
3
  require 'power_stencil/project/paths'
2
4
  require 'power_stencil/project/create'
3
5
  require 'power_stencil/project/config'
@@ -18,13 +18,37 @@ module PowerStencil
18
18
 
19
19
  end
20
20
 
21
+ def plugins_sorted_by_dependency
22
+ solver = PowerStencil::Utils::DependencySolver.new
23
+ plugin_names = plugins.keys
24
+
25
+ plugins.each do |_, plugin|
26
+ unless plugin.dependencies.nil?
27
+ plugin.dependencies.each do |dependency_name|
28
+ raise PowerStencil::Error, "Invalid dependency '#{dependency_name}'declared for plugin '#{plugin.name}' !" unless plugin_names.include? dependency_name
29
+ end
30
+ end
31
+ solver[plugin.name] = plugin.dependencies.nil? ? [] : plugin.dependencies
32
+ end
33
+ solver.tsort.map { |plugin_name| plugins[plugin_name] }
34
+ rescue TSort::Cyclic => e
35
+ PowerStencil::Error.report_error e
36
+ raise PowerStencil::Error, 'Plugins cyclical dependency error !'
37
+ end
38
+
39
+
21
40
  private
22
41
 
23
42
  def bootstrap_plugins
24
43
  @plugins = {}
25
44
  initialize_gem_plugins
26
45
  initialize_local_plugins
46
+ require_plugins_entry_points
27
47
  command_line_manager.definition_hash_to_commands
48
+ register_plugins_processors
49
+ end
50
+
51
+ def register_plugins_processors
28
52
  plugins.each do |_, plugin|
29
53
  if plugin.capabilities[:processors]
30
54
  plugin.register_processors
@@ -32,6 +56,12 @@ module PowerStencil
32
56
  end
33
57
  end
34
58
 
59
+ def require_plugins_entry_points
60
+ plugins_sorted_by_dependency.each do |plugin|
61
+ plugin.require_entry_point
62
+ end
63
+ end
64
+
35
65
  def initialize_gem_plugins
36
66
  if config[:project_plugins].empty?
37
67
  PowerStencil.logger.info 'No gem plugin found in project'
@@ -42,7 +72,8 @@ module PowerStencil
42
72
  (gem_name, gem_req) = PowerStencil::Plugins::Base.plugin_definition_to_name_and_req plugin_definition
43
73
  raise PowerStencil::Error, "Plugin '#{gem_name}' already exists !" unless plugins[gem_name].nil?
44
74
 
45
- plugins[gem_name] = PowerStencil::Plugins::Base.new(gem_name, self, type: :gem, gem_req: gem_req)
75
+ plugin = PowerStencil::Plugins::Base.new(gem_name, self, type: :gem, gem_req: gem_req)
76
+ plugins[plugin.name] = plugin
46
77
  end
47
78
  end
48
79
 
@@ -55,10 +86,12 @@ module PowerStencil
55
86
  Dir.entries(project_local_plugins_path)
56
87
  .select { |e| File.directory? File.join(project_local_plugins_path, e) }
57
88
  .reject { |d| %w(. ..).include? d }
89
+ .sort
58
90
  .each do |candidate|
59
91
  begin
60
92
  raise PowerStencil::Error, "Plugin '#{candidate}' already exists !" unless plugins[candidate].nil?
61
- plugins[candidate] = PowerStencil::Plugins::Base.new(candidate, self)
93
+ plugin = PowerStencil::Plugins::Base.new(candidate, self)
94
+ plugins[plugin.name] = plugin
62
95
  rescue PowerStencil::Error => pse
63
96
  logger.puts_and_logs pse.message, logs_as: :error
64
97
  logger.puts_and_logs "Discarding invalid plugin '#{candidate}'.", logs_as: :error
@@ -0,0 +1,19 @@
1
+ require 'tsort'
2
+
3
+ module PowerStencil
4
+ module Utils
5
+
6
+ class DependencySolver < Hash
7
+
8
+ include TSort
9
+
10
+ alias tsort_each_node each_key
11
+
12
+ def tsort_each_child(node, &block)
13
+ fetch(node).each(&block)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.9.2'.freeze
2
+ VERSION = '0.9.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_stencil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Briais
@@ -307,6 +307,7 @@ files:
307
307
  - lib/power_stencil/ultra_command_line/providers_manager.rb
308
308
  - lib/power_stencil/ultra_command_line/sub_command.rb
309
309
  - lib/power_stencil/utils/completion.rb
310
+ - lib/power_stencil/utils/dependency_solver.rb
310
311
  - lib/power_stencil/utils/directory_processor.rb
311
312
  - lib/power_stencil/utils/file_edit.rb
312
313
  - lib/power_stencil/utils/file_helper.rb
@@ -326,7 +327,7 @@ metadata:
326
327
  documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
327
328
  source_code_uri: https://gitlab.com/tools4devops/power_stencil
328
329
  homepage_uri: https://powerstencil.brizone.org/
329
- post_install_message: "\nThank you for installing PowerStencil 0.9.2 !\nFrom the command
330
+ post_install_message: "\nThank you for installing PowerStencil 0.9.3 !\nFrom the command
330
331
  line you can run `power_stencil --help`\nIf your shell is not completing the command:\n
331
332
  \ If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial Website
332
333
  \ : https://powerstencil.brizone.org/\nFull documentation here : https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel