Refactor helper function '_get_pip' to handle the cases where an absolute

path explicit executable is passed to the task and to look for an explicit executable
by basename in a virtualenv if that is specified.
reviewable/pr18780/r1
Pedro Romano 11 years ago committed by Michael DeHaan
parent 8a843e997f
commit 1391add126

@ -153,26 +153,34 @@ def _get_full_name(name, version=None):
return resp
def _get_pip(module, env, executable=None):
if executable is None:
# Default pip executables.
def _get_pip(module, env=None, executable=None):
# On Debian and Ubuntu, pip is pip.
# On Fedora18 and up, pip is python-pip.
# On Fedora17 and below, CentOS and RedHat 6 and 5, pip is pip-python.
# On Fedora, CentOS, and RedHat, the exception is in the virtualenv.
# There, pip is just pip.
# Try pip with the virtualenv directory first.
pip = module.get_bin_path('pip', False, ['%s/bin' % env])
for p in ['python-pip', 'pip-python']:
if not pip:
pip = module.get_bin_path(p, False, ['%s/bin' % env])
# pip should have been found by now. The final call to get_bin_path
# will trigger fail_json.
if not pip:
pip = module.get_bin_path('pip', True, ['%s/bin' % env])
candidate_pip_basenames = ['pip', 'python-pip', 'pip-python']
pip = None
if executable is not None:
if os.path.isabs(executable):
pip = executable
else:
candidate_pip_basenames.insert(0, executable)
if pip is None:
if env is None:
opt_dirs = []
else:
# Explicit pip executable.
pip = module.get_bin_path(executable, True)
# Try pip with the virtualenv directory first.
opt_dirs = ['%s/bin' % env]
for basename in candidate_pip_basenames:
pip = module.get_bin_path(basename, False, opt_dirs)
if pip is not None:
break
# pip should have been found by now. The final call to get_bin_path will
# trigger fail_json.
if pip is None:
basename = candidate_pip_basenames[0]
pip = module.get_bin_path(basename, True, opt_dirs)
return pip

Loading…
Cancel
Save