dep_selector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ #
2
+ # Author:: Christopher Walters (<cw@opscode.com>)
3
+ # Author:: Mark Anderson (<mark@opscode.com>)
4
+ # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'dep_selector/dependency'
21
+
22
+ class DepSelector::SolutionConstraint < DepSelector::Dependency ; end
@@ -0,0 +1,74 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@opscode.com>)
3
+ # Author:: Christopher Walters (<cw@opscode.com>)
4
+ # Copyright:: Copyright 2010-2011 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'dep_selector/exceptions'
21
+
22
+ module DepSelector
23
+ class Version
24
+ include Comparable
25
+ attr_reader :major, :minor, :patch
26
+
27
+ def initialize(str="")
28
+ @major, @minor, @patch = parse(str)
29
+ end
30
+
31
+ def inspect
32
+ "#{@major}.#{@minor}.#{@patch}"
33
+ end
34
+
35
+ def to_s
36
+ "#{@major}.#{@minor}.#{@patch}"
37
+ end
38
+
39
+ def <=>(v)
40
+ [:major, :minor, :patch].each do |method|
41
+ ans = (self.send(method) <=> v.send(method))
42
+ return ans if ans != 0
43
+ end
44
+ 0
45
+ end
46
+
47
+ def hash
48
+ # Didn't put any thought or research into this, probably can be
49
+ # done better
50
+ to_s.hash
51
+ end
52
+
53
+ # For hash
54
+ def eql?(other)
55
+ other.is_a?(Version) && self == other
56
+ end
57
+
58
+ private
59
+
60
+ def parse(str="")
61
+ @major, @minor, @patch =
62
+ case str.to_s
63
+ when /^(\d+)\.(\d+)\.(\d+)$/
64
+ [ $1.to_i, $2.to_i, $3.to_i ]
65
+ when /^(\d+)\.(\d+)$/
66
+ [ $1.to_i, $2.to_i, 0 ]
67
+ else
68
+ msg = "'#{str.to_s}' does not match 'x.y.z' or 'x.y'"
69
+ raise Exceptions::InvalidVersion.new msg
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,120 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@opscode.com>)
3
+ # Copyright:: Copyright 2010-2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'dep_selector/version'
20
+ require 'dep_selector/exceptions'
21
+
22
+ module DepSelector
23
+ class VersionConstraint
24
+ DEFAULT_CONSTRAINT = ">= 0.0.0"
25
+ STANDARD_OPS = %w(< > <= >=)
26
+ OPS = %w(< > = <= >= ~>)
27
+ PATTERN = /^(#{OPS.join('|')}) (.+)$/
28
+
29
+ attr_reader :op, :version
30
+
31
+ def initialize(constraint_spec=nil)
32
+ constraint_spec ||= DEFAULT_CONSTRAINT
33
+ case constraint_spec
34
+ when nil
35
+ parse(DEFAULT_CONSTRAINT)
36
+ when Array
37
+ parse_from_array(constraint_spec)
38
+ when String
39
+ parse(constraint_spec)
40
+ else
41
+ msg = "VersionConstraint should be created from a String. You gave: #{constraint_spec.inspect}"
42
+ raise Exceptions::InvalidVersionConstraint, msg
43
+ end
44
+ end
45
+
46
+ def include?(v)
47
+ version = if v.respond_to? :version
48
+ Version.new(v.version.to_s)
49
+ else
50
+ Version.new(v.to_s)
51
+ end
52
+ do_op(version)
53
+ end
54
+
55
+ def inspect
56
+ "(#{@op} #{@version})"
57
+ end
58
+
59
+ def to_s
60
+ "#{@op} #{@version}"
61
+ end
62
+
63
+ def eql?(o)
64
+ o.class == self.class && @op == o.op && @version == o.version
65
+ end
66
+ alias_method :==, :eql?
67
+
68
+ private
69
+
70
+ def do_op(other_version)
71
+ if STANDARD_OPS.include? @op
72
+ other_version.send(@op.to_sym, @version)
73
+ elsif @op == '='
74
+ other_version == @version
75
+ elsif @op == '~>'
76
+ if @missing_patch_level
77
+ (other_version.major == @version.major &&
78
+ other_version.minor >= @version.minor)
79
+ else
80
+ (other_version.major == @version.major &&
81
+ other_version.minor == @version.minor &&
82
+ other_version.patch >= @version.patch)
83
+ end
84
+ else # should never happen
85
+ raise "bad op #{@op}"
86
+ end
87
+ end
88
+
89
+ def parse_from_array(constraint_spec)
90
+ if constraint_spec.empty?
91
+ parse(DEFAULT_CONSTRAINT)
92
+ elsif constraint_spec.size == 1
93
+ parse(constraint_spec.first)
94
+ else
95
+ msg = "only one version constraint operation is supported, but you gave #{constraint_spec.size} "
96
+ msg << "['#{constraint_spec.join(', ')}']"
97
+ raise Exceptions::InvalidVersionConstraint, msg
98
+ end
99
+ end
100
+
101
+ def parse(str)
102
+ @missing_patch_level = false
103
+ if str.index(" ").nil? && str =~ /^[0-9]/
104
+ # try for lone version, implied '='
105
+ @version = Version.new(str)
106
+ @op = "="
107
+ elsif PATTERN.match str
108
+ @op = $1
109
+ raw_version = $2
110
+ @version = Version.new(raw_version)
111
+ if raw_version.split('.').count == 2
112
+ @missing_patch_level = true
113
+ end
114
+ else
115
+ raise Exceptions::InvalidVersionConstraint, "'#{str}'"
116
+ end
117
+ end
118
+
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dep_selector
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Walters
9
+ - Mark Anderson
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-03-15 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Given packages, versions, and a dependency graph, find a valid assignment of package versions
19
+ email:
20
+ - cw@opscode.com
21
+ - mark@opscode.com
22
+ executables: []
23
+
24
+ extensions:
25
+ - ext/dep_gecode/extconf.rb
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/dep_selector/densely_packed_set.rb
30
+ - lib/dep_selector/dependency.rb
31
+ - lib/dep_selector/dependency_graph.rb
32
+ - lib/dep_selector/error_reporter/simple_tree_traverser.rb
33
+ - lib/dep_selector/error_reporter.rb
34
+ - lib/dep_selector/exceptions.rb
35
+ - lib/dep_selector/gecode_wrapper.rb
36
+ - lib/dep_selector/package.rb
37
+ - lib/dep_selector/package_version.rb
38
+ - lib/dep_selector/selector.rb
39
+ - lib/dep_selector/solution_constraint.rb
40
+ - lib/dep_selector/version.rb
41
+ - lib/dep_selector/version_constraint.rb
42
+ - lib/dep_selector.rb
43
+ - ext/dep_gecode/dep_selector_swig.i
44
+ - ext/dep_gecode/dep_selector_swig_wrap.cxx
45
+ - ext/dep_gecode/dep_selector_to_gecode.h
46
+ - ext/dep_gecode/dep_selector_to_gecode_interface.h
47
+ - ext/dep_gecode/dep_selector_to_gecode.cpp
48
+ - ext/dep_gecode/dep_selector_to_gecode_interface.cpp
49
+ - ext/dep_gecode/extconf.rb
50
+ - ext/dep_gecode/lib/dep_selector_to_gecode.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/algorist/dep_selector
53
+ licenses:
54
+ - Apache v2
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ requirements:
73
+ - gecode, version 3.5 or greater
74
+ - g++
75
+ rubyforge_project:
76
+ rubygems_version: 1.6.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Given packages, versions, and a dependency graph, find a valid assignment of package versions
80
+ test_files: []
81
+