smarter_bundler 0.1.1 → 0.1.2

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.
data/bin/test CHANGED
@@ -44,21 +44,28 @@ if [ -n "$psych_ver" ]; then
44
44
  fi
45
45
  fi
46
46
 
47
+ if [ $# -gt 0 ]; then
48
+ dirs="$*"
49
+ fi
47
50
  unset BUNDLE_GEMFILE
48
51
  for d in $dirs
49
52
  do
50
- (
51
- echo "======================================================================"
52
- echo "Testing test/$d/Gemfile using ruby $ruby_version ..."
53
- export d
54
- cd test/$d
55
- rm -f Gemfile.lock
56
- cp -f Gemfile.default Gemfile
57
- # Exclude debugger - it breaks for many varied reasons on travis
58
- ../../exe/smarter_bundle --without debug
59
- echo Gemfile changes:
60
- diff Gemfile.default Gemfile
61
- echo
62
- bundle exec ruby -e 'puts "Test of #{ENV['"'"'d'"'"']}/Gemfile with ruby #{RUBY_VERSION} passed at #{Time.now}!"'
63
- )
53
+ if [ -s "test/$d/Gemfile.default" ] ; then
54
+ (
55
+ echo "======================================================================"
56
+ echo "Testing test/$d/Gemfile using ruby $ruby_version ..."
57
+ export d
58
+ cd test/$d
59
+ rm -f Gemfile.lock
60
+ cp -f Gemfile.default Gemfile
61
+ # Exclude debugger - it breaks for many varied reasons on travis
62
+ ../../exe/smarter_bundle --without debug
63
+ echo Gemfile changes:
64
+ diff Gemfile.default Gemfile
65
+ echo
66
+ bundle exec ruby -e 'puts "Test of #{ENV['"'"'d'"'"']}/Gemfile with ruby #{RUBY_VERSION} passed at #{Time.now}!"'
67
+ )
68
+ else
69
+ echo "Missing: test/$d/Gemfile.default - skipped"
70
+ fi
64
71
  done
@@ -1,4 +1,7 @@
1
1
  require 'fileutils'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'yaml'
2
5
 
3
6
  module SmarterBundler
4
7
 
@@ -6,18 +9,19 @@ module SmarterBundler
6
9
  include SmarterBundler::Shell
7
10
 
8
11
  KNOWN_ISSUES_192 = {
9
- 'unicorn' => '5.0',
10
- #'nokogiri' => '1.6.0',
11
- 'jbuilder' => '2.0.0',
12
- }
13
-
12
+ 'unicorn' => '5.0',
13
+ 'nokogiri' => '1.6.0',
14
+ 'jbuilder' => '2.0.0',
15
+ 'factory_girl' => '3.0',
16
+ 'factory_bot' => '3.0',
17
+ }
14
18
 
15
19
 
16
20
  def run(bundle_args)
17
21
  puts "Smarter Bundler will recursively install your gems and output the successful bundler output. This may take a while."
18
22
  count = 0
19
23
  gemfile = SmarterBundler::Gemfile.new
20
- previous_failure = [ ]
24
+ previous_failure = []
21
25
  result = nil
22
26
  while count < 100
23
27
  result = call_bundle(bundle_args)
@@ -29,11 +33,14 @@ module SmarterBundler
29
33
  end
30
34
  previous_failure = failed_gem_and_version
31
35
  gem, version = *failed_gem_and_version
32
- if install_failed_gem gem, version
36
+ if !ruby_version_clash(result) && install_failed_gem(gem, version)
33
37
  puts "Retrying seems to have fixed the problem"
34
38
  elsif gemfile.restrict_gem_version(gem, known_issues(gem))
35
39
  gemfile.save
36
40
  count += 1
41
+ elsif ruby_version_clash(result) && gemfile.restrict_gem_version(gem, rubygems_earlier_version(gem, version))
42
+ gemfile.save
43
+ count += 1
37
44
  elsif ruby_version_clash(result) && gemfile.restrict_gem_version(gem, version)
38
45
  gemfile.save
39
46
  count += 1
@@ -58,7 +65,7 @@ module SmarterBundler
58
65
  end
59
66
 
60
67
  def ruby_version_clash(result)
61
- result.output.select{|l| l =~ /requires Ruby version/}.any?
68
+ result.output.select { |l| l =~ /requires Ruby version/ }.any?
62
69
  end
63
70
 
64
71
  def known_issues(gem)
@@ -78,6 +85,81 @@ module SmarterBundler
78
85
  nil
79
86
  end
80
87
 
88
+ def rubygems_earlier_version(gem, version)
89
+ @rubygems_cache = {}
90
+ @platforms ||= begin
91
+ if RUBY_PLATFORM =~ /linux/
92
+ ['', 'ruby', 'mri']
93
+ else
94
+ [RUBY_PLATFORM]
95
+ end
96
+ end
97
+ @rubygems_cache[gem] ||= begin
98
+ url = "https://rubygems.org/api/v1/versions/#{gem}.yaml"
99
+
100
+ uri = URI.parse(url)
101
+ req = Net::HTTP::Get.new(uri.request_uri)
102
+ http = Net::HTTP.new(uri.host, uri.port)
103
+ http.use_ssl = (uri.scheme == 'https')
104
+ response = http.request(req)
105
+
106
+ text = response.body
107
+ list = YAML.load(text)
108
+ # puts "Request returned list: #{list.inspect}"
109
+ list = list.select { |h| @platforms.include?(h['platform'].to_s) && !h['prerelease'] }.map do |h|
110
+ h.reject do |k, v|
111
+ %w{authors built_at created_at description downloads_count metadata summary rubygems_version licenses requirements sha}.include? k
112
+ end
113
+ end
114
+ # puts "Trimmed prerelease list: #{list.inspect}"
115
+ list
116
+ # rescue RuntimeError => ex
117
+ # puts "Ignoring exception: #{ex} - we will have to work it out the slow way"
118
+ # []
119
+ end
120
+ list = @rubygems_cache[gem]
121
+ if list.size == 0
122
+ puts "Unable to find version info at rubygems for #{gem}"
123
+ return nil
124
+ end
125
+ current = list.select { |h| h['number'] == version }.first
126
+ if current.nil?
127
+ puts "Unable to find current version info at rubygems for #{gem}, version #{version}"
128
+ return nil
129
+ end
130
+ puts "Found record for current version: #{current.inspect}"
131
+ current_ruby_version = current['ruby_version']
132
+ # puts "current ruby_version: #{current_ruby_version.inspect}"
133
+ if current_ruby_version.nil?
134
+ puts "Rubygems has nil ruby_version spec for #{gem} #{version} - unable to pick next version"
135
+ return nil
136
+ end
137
+ found = false
138
+ same_versions = list.select do |h|
139
+ (h['ruby_version'] == current_ruby_version) && (h['number'] !~ /[a-z]/i)
140
+ end
141
+ next_version = same_versions.map { |h| h['number'] }.last
142
+ puts "Selected next_version: #{next_version}"
143
+ next_version
144
+ # [
145
+ # {"authors":"Evan David Light",
146
+ # "built_at":"2011-08-08T04:00:00.000Z",
147
+ # "created_at":"2011-08-08T21:23:40.254Z",
148
+ # "description":"Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse",
149
+ # "downloads_count":3493,
150
+ # "metadata":{},
151
+ # "number":"0.7.1",
152
+ # "summary":"Test::Unit-based acceptance testing DSL",
153
+ # "platform":"ruby",
154
+ # "rubygems_version":"\u003e= 0",
155
+ # "ruby_version":null,
156
+ # "prerelease":false,
157
+ # "licenses":null,
158
+ # "requirements":null,
159
+ # "sha":"777c3a7ed83e44198b0a624976ec99822eb6f4a44bf1513eafbc7c13997cd86c"},
160
+ end
161
+
162
+
81
163
  end
82
164
 
83
165
  end
@@ -21,18 +21,27 @@ module SmarterBundler
21
21
  end
22
22
  adjusted = false
23
23
  @contents.map! do |line|
24
- if line =~ /^(\s*gem\s+['"]#{gem}['"])(\s*,\*['"]([^'"]*)['"])?(.*?)$/
24
+ if line =~ /^(\s*gem\s+['"]#{gem}['"])(.*)$/
25
25
  gem_and_name = $1
26
- rest_of_line = $4
27
- version = $3.to_s
28
- puts "Found #{gem_name_name} with version spec: #{version} and other args: #{rest_of_line}"
29
- new_version = version.sub(/<=?\s*[^,\s]+/, '').sub(/^\s*,\s*/, '').sub(/\s*,\s*$/, '') + (version == '' ? '' : ', ') + "< #{version_limit}"
30
- puts " Calculated new_version spec: #{new_version}"
31
- if new_version != version
26
+ rest_of_line = $2
27
+ versions = [ ]
28
+ if rest_of_line =~ /^\s*,\s*['"]([^'"]*)['"](.*)/
29
+ versions = [ $1 ]
30
+ rest_of_line = $2
31
+ elsif rest_of_line =~ /^\s*,\s*\[([^\]]*)\](.*)/
32
+ rest_of_line = $2
33
+ versions = $1.split(',').map{|s| s.sub(/^[\s'"]*/, '').sub(/[\s'"]*$/, '')}
34
+ end
35
+ #puts "Found #{gem_and_name} in Gemfile with version spec: #{versions.inspect} and other args: #{rest_of_line}"
36
+ new_versions = versions.dup
37
+ new_versions.delete_if{|s| s =~ /</}
38
+ new_versions << "< #{version_limit}"
39
+ #puts " Replacing with new version spec: #{new_versions.inspect}"
40
+ if new_versions != versions
32
41
  @changed = true
33
42
  rest_of_line.sub!(/ # REQUIRED - Added by SmarterBundler.*/, '')
34
43
  rest_of_line << ' # REQUIRED - Added by SmarterBundler'
35
- line = "#{gem_and_name}, '#{new_version}'#{rest_of_line}"
44
+ line = "#{gem_and_name}, #{new_versions.inspect}#{rest_of_line}"
36
45
  puts "Changed Gemfile line to: #{line}"
37
46
  line
38
47
  else
@@ -53,6 +62,7 @@ module SmarterBundler
53
62
  end
54
63
  FileUtils.move "#{@filename}.new", @filename, :force => true
55
64
  @changed = false
65
+ puts 'Currently restricted:', *(@contents.select{|line| line =~ /Added by SmartBundler/})
56
66
  end
57
67
  end
58
68
 
@@ -1,3 +1,3 @@
1
1
  module SmarterBundler
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -99,13 +99,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: 1603618397689055998
102
+ hash: 2247782191630905192
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  none: false
105
105
  requirements:
106
106
  - - ! '>='
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 2247782191630905192
109
112
  requirements: []
110
113
  rubyforge_project:
111
114
  rubygems_version: 1.8.23.2