pub_grub 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4199b218840d39743919d5befd111f71335aecd06d0f4f09dcc9ae168fc5f04d
4
+ data.tar.gz: 619cca849d88ab3173f2e71f37ff6acdd3be212d7d099c329de0685a102e85fd
5
+ SHA512:
6
+ metadata.gz: d17dc7b3fb90bf613053c5eeb92893468af588a46009c3c847aab45f629eb21871cbca9a3f2a7e525cc77ab14896ad0aec8d0faee786e71cb4b9f81202b759b3
7
+ data.tar.gz: b76ac52d2b0b8fcdce473c4233f2873c7bd88d6ada06a70b9c610500ec338ebef2f3eea8d3b2185203282ef3acff637c2ad81fd62dee6127a32fa800d545c68b
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at john@hawthorn.email. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pub_grub.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pub_grub (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.16)
17
+ minitest (~> 5.0)
18
+ pub_grub!
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 John Hawthorn
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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ [![Build Status](https://travis-ci.org/jhawthorn/pub_grub.svg?branch=master)](https://travis-ci.org/jhawthorn/pub_grub)
2
+
3
+ # PubGrub
4
+
5
+ An attempt to implement [Natalie Weizenbaum's PubGrub](https://medium.com/@nex3/pubgrub-2fb6470504f), a next-generation version solving algorithm, in Ruby.
6
+
7
+ ## Development
8
+
9
+ 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.
10
+
11
+ 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).
12
+
13
+ ## Contributing
14
+
15
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jhawthorn/pub_grub.
16
+
17
+ ## License
18
+
19
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
20
+
21
+ ## Code of Conduct
22
+
23
+ Everyone interacting in the PubGrub project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jhawthorn/pub_grub/blob/master/CODE_OF_CONDUCT.md).
24
+
25
+ ## See Also
26
+
27
+ * [PubGrub: Next-Generation Version Solving - Natalie Weizenbaum - Medium](https://medium.com/@nex3/pubgrub-2fb6470504f)
28
+ * [PubGrub - doc/solver.md - github](https://github.com/dart-lang/pub/blob/master/doc/solver.md)
data/Rakefile ADDED
@@ -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 => :test
data/bin/console ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pub_grub"
5
+
6
+ source =
7
+ PubGrub::StaticPackageSource.new do |s|
8
+ s.add "foo", "2.0.0", deps: { "bar" => "~> 2.0" }
9
+ s.add "foo", "1.1.0", deps: { "bar" => "~> 1.0" }
10
+ s.add "foo", "1.0.0", deps: { "bar" => "~> 1.0" }
11
+
12
+ s.add "bar", "2.0.0"
13
+ s.add "bar", "1.0.0"
14
+ end
15
+
16
+ foo = source.get_package("foo")
17
+ bar = source.get_package("bar")
18
+
19
+ solver = VersionSolver.new(source: source)
20
+
21
+ require 'irb'
22
+ IRB.setup(__FILE__)
23
+ workspace = IRB::WorkSpace.new(binding)
24
+ IRB::Irb.new(workspace).run(IRB.conf)
data/bin/setup ADDED
@@ -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
data/lib/pub_grub.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "pub_grub/package"
2
+ require "pub_grub/static_package_source"
3
+ require "pub_grub/term"
4
+ require "pub_grub/version_constraint"
5
+ require "pub_grub/version_solver"
6
+ require "pub_grub/incompatibility"
7
+ require 'pub_grub/solve_failure'
8
+ require 'pub_grub/failure_writer'
9
+
10
+ require "logger"
11
+
12
+ module PubGrub
13
+ class << self
14
+ attr_accessor :logger
15
+ end
16
+ self.logger = Logger.new(STDERR)
17
+ self.logger.level = Logger::WARN
18
+ end
@@ -0,0 +1,20 @@
1
+ module PubGrub
2
+ class Assignment
3
+ attr_reader :term, :cause, :decision_level, :index
4
+ def initialize(term, cause, decision_level, index)
5
+ @term = term
6
+ @cause = cause
7
+ @decision_level = decision_level
8
+ @index = index
9
+ end
10
+
11
+ def self.decision(version, decision_level, index)
12
+ term = Term.new(VersionConstraint.exact(version), true)
13
+ new(term, :decision, decision_level, index)
14
+ end
15
+
16
+ def decision?
17
+ cause == :decision
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,179 @@
1
+ module PubGrub
2
+ class FailureWriter
3
+ def initialize(root)
4
+ @root = root
5
+
6
+ # { Incompatibility => Integer }
7
+ @derivations = {}
8
+
9
+ # [ [ String, Integer or nil ] ]
10
+ @lines = []
11
+
12
+ # { Incompatibility => Integer }
13
+ @line_numbers = {}
14
+
15
+ count_derivations(root)
16
+ end
17
+
18
+ def write
19
+ visit(@root)
20
+
21
+ padding = @line_numbers.empty? ? 0 : "(#{@line_numbers.values.last}) ".length
22
+
23
+ @lines.map do |message, number|
24
+ next "" if message.empty?
25
+
26
+ lead = number ? "(#{number}) " : ""
27
+ lead = lead.ljust(padding)
28
+ "#{lead}#{message}"
29
+ end.join("\n")
30
+ end
31
+
32
+ private
33
+
34
+ def write_line(incompatibility, message, numbered:)
35
+ if numbered
36
+ number = @line_numbers.length + 1
37
+ @line_numbers[incompatibility] = number
38
+ end
39
+
40
+ @lines << [message, number]
41
+ end
42
+
43
+ def visit(incompatibility, conclusion: false)
44
+ raise unless incompatibility.conflict?
45
+
46
+ numbered = conclusion || @derivations[incompatibility] > 1;
47
+ conjunction = conclusion || incompatibility == @root ? "So," : "And"
48
+
49
+ cause = incompatibility.cause
50
+
51
+ if cause.conflict.conflict? && cause.other.conflict?
52
+ conflict_line = @line_numbers[cause.conflict]
53
+ other_line = @line_numbers[cause.other]
54
+
55
+ if conflict_line && other_line
56
+ write_line(
57
+ incompatibility,
58
+ "Because #{cause.conflict} (#{conflict_line}) and #{cause.other} (#{other_line}), #{incompatibility}.",
59
+ numbered: numbered
60
+ )
61
+ elsif conflict_line || other_line
62
+ with_line = conflict_line ? cause.conflict : cause.other
63
+ without_line = conflict_line ? cause.other : cause.conflict
64
+ line = @line_numbers[with_line]
65
+
66
+ visit(without_line);
67
+ write_line(
68
+ incompatibility,
69
+ "#{conjunction} because #{with_line} (#{line}), #{incompatibility}.",
70
+ numbered: numbered
71
+ )
72
+ else
73
+ single_line_conflict = single_line?(cause.conflict.cause)
74
+ single_line_other = single_line?(cause.other.cause)
75
+
76
+ if single_line_conflict || single_line_other
77
+ first = single_line_other ? cause.conflict : cause.other
78
+ second = single_line_other ? cause.other : cause.conflict
79
+ visit(first)
80
+ visit(second)
81
+ write_line(
82
+ incompatibility,
83
+ "Thus, #{incompatibility}.",
84
+ numbered: numbered
85
+ )
86
+ else
87
+ visit(cause.conflict, conclusion: true)
88
+ @lines << ["", nil]
89
+ visit(cause.other)
90
+
91
+ write_line(
92
+ incompatibility,
93
+ "#{conjunction} because #{cause.conflict} (#{@line_numbers[cause.conflict]}), #{incompatibility}.",
94
+ numbered: numbered
95
+ )
96
+ end
97
+ end
98
+ elsif cause.conflict.conflict? || cause.other.conflict?
99
+ derived = cause.conflict.conflict? ? cause.conflict : cause.other
100
+ ext = cause.conflict.conflict? ? cause.other : cause.conflict
101
+
102
+ derived_line = @line_numbers[derived]
103
+ if derived_line
104
+ write_line(
105
+ incompatibility,
106
+ "Because #{ext} and #{derived} (#{derived_line}), #{incompatibility}.",
107
+ numbered: numbered
108
+ )
109
+ elsif collapsible?(derived)
110
+ derived_cause = derived.cause
111
+ if derived_cause.conflict.conflict?
112
+ collapsed_derived = derived_cause.conflict
113
+ collapsed_ext = derived_cause.other
114
+ else
115
+ collapsed_derived = derived_cause.other
116
+ collapsed_ext = derived_cause.conflict
117
+ end
118
+
119
+ visit(collapsed_derived)
120
+
121
+ write_line(
122
+ incompatibility,
123
+ "#{conjunction} because #{collapsed_ext} and #{ext}, #{incompatibility}.",
124
+ numbered: numbered
125
+ )
126
+ else
127
+ visit(derived)
128
+ write_line(
129
+ incompatibility,
130
+ "#{conjunction} because #{ext}, #{incompatibility}.",
131
+ numbered: numbered
132
+ )
133
+ end
134
+ else
135
+ write_line(
136
+ incompatibility,
137
+ "Because #{cause.conflict} and #{cause.other}, #{incompatibility}.",
138
+ numbered: numbered
139
+ )
140
+ end
141
+ end
142
+
143
+ def single_line?(cause)
144
+ !cause.conflict.conflict? && !cause.other.conflict?
145
+ end
146
+
147
+ def collapsible?(incompatibility)
148
+ return false if @derivations[incompatibility] > 1
149
+
150
+ cause = incompatibility.cause
151
+ # If incompatibility is derived from two derived incompatibilities,
152
+ # there are too many transitive causes to display concisely.
153
+ return false if cause.conflict.conflict? && cause.other.conflict?
154
+
155
+ # If incompatibility is derived from two external incompatibilities, it
156
+ # tends to be confusing to collapse it.
157
+ return false unless cause.conflict.conflict? || cause.other.conflict?
158
+
159
+ # If incompatibility's internal cause is numbered, collapsing it would
160
+ # get too noisy.
161
+ complex = cause.conflict.conflict? ? cause.conflict : cause.other
162
+
163
+ !@line_numbers.has_key?(complex)
164
+ end
165
+
166
+ def count_derivations(incompatibility)
167
+ if @derivations.has_key?(incompatibility)
168
+ @derivations[incompatibility] += 1
169
+ else
170
+ @derivations[incompatibility] = 1
171
+ if incompatibility.conflict?
172
+ cause = incompatibility.cause
173
+ count_derivations(cause.conflict)
174
+ count_derivations(cause.other)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end