|
20 | 20 |
|
21 | 21 | require 'chef/mixin/shell_out'
|
22 | 22 | require 'chef/mixin/language'
|
| 23 | +require 'version' |
23 | 24 | include Chef::Mixin::ShellOut
|
24 | 25 |
|
25 | 26 | def whyrun_supported?
|
@@ -117,11 +118,28 @@ def current_installed_version
|
117 | 118 | end
|
118 | 119 |
|
119 | 120 | def candidate_version
|
| 121 | + yolk_path = which_yolk(new_resource) |
120 | 122 | @candidate_version ||= begin
|
121 |
| - # `pip search` doesn't return versions yet |
122 |
| - # `pip list` may be coming soon: |
123 |
| - # https://bitbucket.org/ianb/pip/issue/197/option-to-show-what-version-would-be |
124 |
| - new_resource.version||'latest' |
| 123 | + # if yolk is installed, check if a newer version is available in PyPi |
| 124 | + # then check if newer version is greater then the version specified by new_resource |
| 125 | + # return as appropriate |
| 126 | + if ::File.exists?(yolk_path) then |
| 127 | + out = shell_out("#{yolk_path} -U #{new_resource.package_name}").stdout |
| 128 | + if out.match(/not installed/) then |
| 129 | + new_resource.version||'latest' |
| 130 | + elsif out.match(/#{new_resource.package_name} [\d\.]+ \([\d\.]+\)/) then |
| 131 | + available_version = Version.new(out.split(' ').last.tr('()','')) |
| 132 | + if available_version > ( Version.new(new_resource.version) || Version.new('0.0') ) |
| 133 | + new_resource.version |
| 134 | + else |
| 135 | + available_version |
| 136 | + end |
| 137 | + else |
| 138 | + current_installed_version |
| 139 | + end |
| 140 | + else |
| 141 | + new_resource.version||'latest' |
| 142 | + end |
125 | 143 | end
|
126 | 144 | end
|
127 | 145 |
|
@@ -166,3 +184,13 @@ def which_pip(nr)
|
166 | 184 | 'pip'
|
167 | 185 | end
|
168 | 186 | end
|
| 187 | + |
| 188 | +def which_yolk(nr) |
| 189 | + if (nr.respond_to?("virtualenv") && nr.virtualenv) |
| 190 | + ::File.join(nr.virtualenv,'/bin/yolk') |
| 191 | + elsif ::File.exists?(node['python']['yolk_location']) |
| 192 | + node['python']['yolk_location'] |
| 193 | + else |
| 194 | + 'yolk' |
| 195 | + end |
| 196 | +end |
0 commit comments