Handling empty strings passed as pip_install_command.

This commit is contained in:
Vidroha Debroy 2019-01-25 14:55:39 -06:00
parent 2b0617fb64
commit 84df098135
2 changed files with 19 additions and 1 deletions

View File

@ -5,6 +5,8 @@ module VagrantPlugins
module Guest module Guest
module Pip module Pip
DEFAULT_PIP_INSTALL_CMD = "curl https://bootstrap.pypa.io/get-pip.py | sudo python"
def self.pip_install(machine, package = "", version = "", pip_args = "", upgrade = true) def self.pip_install(machine, package = "", version = "", pip_args = "", upgrade = true)
upgrade_arg = "--upgrade" if upgrade upgrade_arg = "--upgrade" if upgrade
version_arg = "" version_arg = ""
@ -18,7 +20,17 @@ module VagrantPlugins
machine.communicate.sudo "pip install #{args_array.join(' ')}" machine.communicate.sudo "pip install #{args_array.join(' ')}"
end end
def self.get_pip(machine, pip_install_cmd="curl https://bootstrap.pypa.io/get-pip.py | sudo python") def self.get_pip(machine, pip_install_cmd=DEFAULT_PIP_INSTALL_CMD)
# The objective here is to get pip either by default
# or by the argument passed in. The objective is not
# to circumvent the pip setup by passing in nothing.
# Thus, we stick with the default on an empty string.
if pip_install_cmd.empty?
pip_install_cmd=DEFAULT_PIP_INSTALL_CMD
end
machine.ui.detail I18n.t("vagrant.provisioners.ansible.installing_pip") machine.ui.detail I18n.t("vagrant.provisioners.ansible.installing_pip")
machine.communicate.execute pip_install_cmd machine.communicate.execute pip_install_cmd
end end

View File

@ -36,6 +36,12 @@ describe VagrantPlugins::Ansible::Cap::Guest::Pip do
expect(communicator).to receive(:execute).with(pip_install_command) expect(communicator).to receive(:execute).with(pip_install_command)
subject.get_pip(machine,pip_install_command) subject.get_pip(machine,pip_install_command)
end end
it "installs pip using the default command if the argument is empty" do
pip_install_command = ""
expect(communicator).to receive(:execute).with("curl https://bootstrap.pypa.io/get-pip.py | sudo python")
subject.get_pip(machine,pip_install_command)
end
end end
end end
end end