grimoire 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/grimoire.rb +28 -0
- data/lib/grimoire/requirement_list.rb +1 -1
- data/lib/grimoire/solver.rb +23 -11
- data/lib/grimoire/system.rb +11 -0
- data/lib/grimoire/unit.rb +2 -2
- data/lib/grimoire/utility.rb +6 -0
- data/lib/grimoire/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e488dfe4964214969754e066c275034a4663d67
|
4
|
+
data.tar.gz: 015e51d0f9a05e51a00b5f0b41c4de77764c77f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4756adf5a06f61ed26b4732e7f8848b1a063f47372577578038be52ff8532e31d2c0f8e789612d9131d23aad8c27528fad05753d751b4bef6f821f8670253ce
|
7
|
+
data.tar.gz: 387138f63f6e94ee25c359be79359266721441b3f0779452fc20f871f525f1e2df03954a43702cf9473de8c10899c2249aa6ca547a2df7cad887d632dced909e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# v0.1.6
|
2
|
+
* Add debug output if UI is available for output
|
3
|
+
* Update exception errors to provide more detail/context
|
4
|
+
* Provide better type checking prior to processing
|
5
|
+
|
1
6
|
# v0.1.4
|
2
7
|
* Provide simple system serialization support
|
3
8
|
* Fix dependency listing from units within path
|
data/README.md
CHANGED
data/lib/grimoire.rb
CHANGED
@@ -20,6 +20,34 @@ module Grimoire
|
|
20
20
|
autoload :UnitScoreKeeper, 'grimoire/unit_score_keeper'
|
21
21
|
autoload :Utility, 'grimoire/utility'
|
22
22
|
|
23
|
+
class << self
|
24
|
+
|
25
|
+
# @return [Bogo::Ui]
|
26
|
+
attr_reader :ui
|
27
|
+
|
28
|
+
# Set Ui instance
|
29
|
+
#
|
30
|
+
# @param ui [Bogo::Ui]
|
31
|
+
# @return [Bogo::Ui]
|
32
|
+
def ui=(ui)
|
33
|
+
unless(ui.respond_to?(:debug))
|
34
|
+
raise TypeError.new "Expecting type `Bogo::Ui` but received `#{ui.class}`"
|
35
|
+
end
|
36
|
+
@ui = ui
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Write debug message
|
41
|
+
def debug(*args)
|
42
|
+
if(ui)
|
43
|
+
if(block_given?)
|
44
|
+
args.push(yield)
|
45
|
+
end
|
46
|
+
ui.debug(*args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
23
51
|
end
|
24
52
|
|
25
53
|
require 'grimoire/version'
|
@@ -5,7 +5,7 @@ module Grimoire
|
|
5
5
|
# Requirment list for solver
|
6
6
|
class RequirementList < Utility
|
7
7
|
attribute :name, String, :required => true, :coerce => lambda{|val| val.to_s}
|
8
|
-
attribute :requirements, DEPENDENCY_CLASS, :multiple => true, :default => [], :coerce => lambda{|val| DEPENDENCY_CLASS.new(val.first, *val.last)}
|
8
|
+
attribute :requirements, DEPENDENCY_CLASS, :multiple => true, :default => [], :coerce => lambda{|val| Grimoire.const_get(:DEPENDENCY_CLASS).new(val.first, *val.last)}
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
data/lib/grimoire/solver.rb
CHANGED
@@ -13,6 +13,7 @@ module Grimoire
|
|
13
13
|
attribute :requirements, RequirementList, :required => true
|
14
14
|
attribute :system, System, :required => true
|
15
15
|
attribute :score_keeper, UnitScoreKeeper
|
16
|
+
attribute :result_limit, Integer, :required => true, :default => 1
|
16
17
|
|
17
18
|
# @return [System] subset of full system based on requirements
|
18
19
|
attr_reader :world
|
@@ -39,11 +40,16 @@ module Grimoire
|
|
39
40
|
deps.each do |dep|
|
40
41
|
units = root.subset(dep.name, dep.requirement)
|
41
42
|
sha = Digest::SHA256.hexdigest(MultiJson.dump(units))
|
42
|
-
|
43
|
+
if(@log.include?(sha))
|
44
|
+
debug "Units checksum already added to world. Skipping. (`#{sha}`)"
|
45
|
+
next
|
46
|
+
end
|
47
|
+
debug "Logging units checksum for world addition. (`#{sha}`)"
|
43
48
|
@log.push(sha)
|
44
49
|
units.each do |unit|
|
45
50
|
build_world(unit.dependencies, my_world, root)
|
46
51
|
end
|
52
|
+
debug "Units added to world: #{MultiJson.dump(units.map{|u| {u.name => u.version} })}"
|
47
53
|
my_world.add_unit(units)
|
48
54
|
end
|
49
55
|
end
|
@@ -108,6 +114,9 @@ module Grimoire
|
|
108
114
|
# @raises [Error::UnitUnavailable]
|
109
115
|
def unit_for(dep)
|
110
116
|
unit = nil
|
117
|
+
if(queues[dep.name].nil?)
|
118
|
+
raise KeyError.new "No valid units for requested name found within system! (`#{dep.name}`)"
|
119
|
+
end
|
111
120
|
until(unit || queues[dep.name].empty?)
|
112
121
|
unit = queues[dep.name].pop
|
113
122
|
unit = nil unless dep.requirement.satisfied_by?(unit.version)
|
@@ -158,7 +167,8 @@ module Grimoire
|
|
158
167
|
end
|
159
168
|
end
|
160
169
|
end
|
161
|
-
rescue Error::ResolutionPathInvalid
|
170
|
+
rescue Error::ResolutionPathInvalid => e
|
171
|
+
debug "Resolution path deadend: #{e} (trying new path)"
|
162
172
|
retry
|
163
173
|
end
|
164
174
|
deps.uniq
|
@@ -169,30 +179,32 @@ module Grimoire
|
|
169
179
|
#
|
170
180
|
# @return [Bogo::PriorityQueue<Path>]
|
171
181
|
def generate!
|
182
|
+
if(requirements.requirements.empty?)
|
183
|
+
raise ArgumentError.new 'No cookbook constraints provided within Batali file!'
|
184
|
+
end
|
172
185
|
custom_unit = Unit.new(
|
173
186
|
:name => '~_SOLVER_UNIT_~',
|
174
187
|
:version => '1.0.0',
|
175
188
|
:dependencies => requirements.requirements
|
176
189
|
)
|
177
190
|
count = 0
|
191
|
+
debug "Solver Unit: #{MultiJson.dump(custom_unit)}"
|
192
|
+
debug{ "Solver world context of unit system: #{world.inspect}" }
|
178
193
|
results = Bogo::PriorityQueue.new
|
179
194
|
begin
|
180
|
-
until(count
|
195
|
+
until(count >= result_limit)
|
181
196
|
result = resolve(nil, custom_unit)
|
182
197
|
results.push(Path.new(:units => result.slice(1, result.size)), count)
|
183
198
|
count += 1
|
184
199
|
end
|
185
|
-
rescue Error::UnitUnavailable
|
200
|
+
rescue Error::UnitUnavailable => e
|
201
|
+
debug "Failed to unit: #{e}"
|
186
202
|
count = nil
|
187
203
|
end
|
188
|
-
|
189
|
-
raise Error::
|
204
|
+
if(results.empty?)
|
205
|
+
raise Error::NoSolution.new("Failed to generate valid path for requirements: `#{custom_unit.dependencies}`")
|
190
206
|
else
|
191
|
-
|
192
|
-
raise Error::NoSolution.new("Failed to generate valid path for requirements: `#{custom_unit.dependencies.inspect}`")
|
193
|
-
else
|
194
|
-
results
|
195
|
-
end
|
207
|
+
results
|
196
208
|
end
|
197
209
|
end
|
198
210
|
|
data/lib/grimoire/system.rb
CHANGED
@@ -58,6 +58,9 @@ module Grimoire
|
|
58
58
|
unless(constraint.respond_to?(:requirements))
|
59
59
|
raise TypeError.new "Expecting `#{REQUIREMENT_CLASS}` but received `#{constraint.class}`"
|
60
60
|
end
|
61
|
+
unless(units[unit_name])
|
62
|
+
raise KeyError.new("Failed to locate any units loaded in system with requested name: `#{unit_name}`")
|
63
|
+
end
|
61
64
|
units[unit_name].find_all do |unit|
|
62
65
|
constraint.satisfied_by?(unit.version)
|
63
66
|
end
|
@@ -83,5 +86,13 @@ module Grimoire
|
|
83
86
|
)
|
84
87
|
end
|
85
88
|
|
89
|
+
# @return [String]
|
90
|
+
def inspect
|
91
|
+
"<#{self.class}:#{self.object_id}>: " <<
|
92
|
+
units.to_a.sort_by(&:first).map do |name, units|
|
93
|
+
"#{name}: #{units.map(&:version).sort.map(&:to_s).join(', ')}"
|
94
|
+
end.join("\n")
|
95
|
+
end
|
96
|
+
|
86
97
|
end
|
87
98
|
end
|
data/lib/grimoire/unit.rb
CHANGED
@@ -6,8 +6,8 @@ module Grimoire
|
|
6
6
|
class Unit < Utility
|
7
7
|
|
8
8
|
attribute :name, String, :required => true
|
9
|
-
attribute :dependencies, DEPENDENCY_CLASS, :multiple => true, :default => [], :coerce => lambda{|val| DEPENDENCY_CLASS.new(val.first, *val.last)}
|
10
|
-
attribute :version, VERSION_CLASS, :required => true, :coerce => lambda{|val| VERSION_CLASS.new(val)}
|
9
|
+
attribute :dependencies, DEPENDENCY_CLASS, :multiple => true, :default => [], :coerce => lambda{|val| Grimoire.const_get(:DEPENDENCY_CLASS).new(val.first, *val.last)}
|
10
|
+
attribute :version, VERSION_CLASS, :required => true, :coerce => lambda{|val| Grimoire.const_get(:VERSION_CLASS).new(val)}
|
11
11
|
|
12
12
|
end
|
13
13
|
|
data/lib/grimoire/utility.rb
CHANGED
data/lib/grimoire/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grimoire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|