From cf239da7df609476ac2910e79f4d5a98305302ed Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 23 Jun 2022 20:44:44 +0100 Subject: [PATCH] Add an upgrade action for the python_package resource --- cookbooks/python/resources/package.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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}" -- 2.43.2