From: Tom Hughes Date: Thu, 23 Jun 2022 19:44:44 +0000 (+0100) Subject: Add an upgrade action for the python_package resource X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/cf239da7df609476ac2910e79f4d5a98305302ed Add an upgrade action for the python_package resource --- diff --git a/cookbooks/python/resources/package.rb b/cookbooks/python/resources/package.rb index 0a3f49170..c838690af 100644 --- a/cookbooks/python/resources/package.rb +++ b/cookbooks/python/resources/package.rb @@ -40,6 +40,20 @@ action :install do end end +action :upgrade do + if new_resource.version.nil? + execute "pip-upgrade-#{new_resource.package_name}" do + command "#{pip_command} install --upgrade #{new_resource.package_name}" + only_if "#{pip_command} list --outdated | fgrep -q #{new_resource.package_name}" + end + else + execute "pip-upgrade-#{new_resource.package_name}" do + command "#{pip_command} install --upgrade #{new_resource.package_name}==#{new_resource.version}" + not_if "#{pip_command} show #{new_resource.package_name} | fgrep -q #{new_resource.version}" + end + end +end + action :remove do execute "pip-uninstall-#{new_resource.package_name}" do command "#{pip_command} uninstall #{new_resource.package_name}"