Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow a different source URL for python packages
Browse files Browse the repository at this point in the history
lonvia committed Sep 30, 2024
1 parent 2071840 commit 9f487de
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cookbooks/python/resources/package.rb
Original file line number Diff line number Diff line change
@@ -25,16 +25,17 @@
property :version, :kind_of => String
property :python_version, :kind_of => String
property :python_virtualenv, :kind_of => String
property :extra_index_url, :kind_of => String

action :install do
if new_resource.version.nil?
execute "pip-install-#{new_resource.package_name}" do
command "#{pip_command} install #{new_resource.package_name}"
command "#{pip_command} install #{pip_extra_index} #{new_resource.package_name}"
not_if "#{pip_command} show #{new_resource.package_name}"
end
else
execute "pip-install-#{new_resource.package_name}" do
command "#{pip_command} install #{new_resource.package_name}==#{new_resource.version}"
command "#{pip_command} install #{pip_extra_index} #{new_resource.package_name}==#{new_resource.version}"
not_if "#{pip_command} show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
end
end
@@ -43,12 +44,12 @@
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}"
command "#{pip_command} install #{pip_extra_index} --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}"
command "#{pip_command} install #{pip_extra_index} --upgrade #{new_resource.package_name}==#{new_resource.version}"
not_if "#{pip_command} show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
end
end
@@ -62,6 +63,11 @@
end

action_class do
def pip_extra_index
if new_resource.extra_index_url
"--extra-index-url '#{new_resource.extra_index_url}'"
end
end
def pip_command
if new_resource.python_virtualenv
"#{new_resource.python_virtualenv}/bin/pip"

0 comments on commit 9f487de

Please sign in to comment.