Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7858d43

Browse files
author
Peter Bell
committed
fixed merge conflicts
2 parents a25a617 + e5977be commit 7858d43

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

attributes/default.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@
4444
default['python']['setuptools_version'] = nil # defaults to latest
4545
default['python']['virtualenv_version'] = nil
4646
default['python']['pip_version'] = nil
47+
default['python']['yolk_version'] = nil
48+
default['python']['yolk_location'] = "#{node['python']['prefix_dir']}/bin/yolk"

providers/pip.rb

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
require 'chef/mixin/shell_out'
2222
require 'chef/mixin/language'
23+
require 'version'
2324
include Chef::Mixin::ShellOut
2425

2526
def whyrun_supported?
@@ -117,11 +118,28 @@ def current_installed_version
117118
end
118119

119120
def candidate_version
121+
yolk_path = which_yolk(new_resource)
120122
@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
125143
end
126144
end
127145

@@ -166,3 +184,13 @@ def which_pip(nr)
166184
'pip'
167185
end
168186
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

recipes/pip.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
pip_binary = "/usr/local/bin/pip"
3434
end
3535

36+
chef_gem 'version' do
37+
action :nothing
38+
end.run_action(:install)
39+
3640
cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do
3741
source 'get-pip.py'
3842
mode "0644"
@@ -52,6 +56,11 @@
5256
version node['python']['pip_version']
5357
end
5458

59+
python_pip 'yolk' do
60+
action :upgrade
61+
version node['python']['yolk_version']
62+
end
63+
5564
python_pip 'setuptools' do
5665
action :upgrade
5766
version node['python']['setuptools_version']

0 commit comments

Comments
 (0)