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.
This commit is contained in:
parent
57a71043a3
commit
307dd77589
1 changed files with 28 additions and 20 deletions
|
@ -153,26 +153,34 @@ def _get_full_name(name, version=None):
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
def _get_pip(module, env, executable=None):
|
def _get_pip(module, env=None, executable=None):
|
||||||
if executable is None:
|
# On Debian and Ubuntu, pip is pip.
|
||||||
# Default pip executables.
|
# On Fedora18 and up, pip is python-pip.
|
||||||
# On Debian and Ubuntu, pip is pip.
|
# On Fedora17 and below, CentOS and RedHat 6 and 5, pip is pip-python.
|
||||||
# On Fedora18 and up, pip is python-pip.
|
# On Fedora, CentOS, and RedHat, the exception is in the virtualenv.
|
||||||
# On Fedora17 and below, CentOS and RedHat 6 and 5, pip is pip-python.
|
# There, pip is just pip.
|
||||||
# On Fedora, CentOS, and RedHat, the exception is in the virtualenv.
|
candidate_pip_basenames = ['pip', 'python-pip', 'pip-python']
|
||||||
# There, pip is just pip.
|
pip = None
|
||||||
# Try pip with the virtualenv directory first.
|
if executable is not None:
|
||||||
pip = module.get_bin_path('pip', False, ['%s/bin' % env])
|
if os.path.isabs(executable):
|
||||||
for p in ['python-pip', 'pip-python']:
|
pip = executable
|
||||||
if not pip:
|
else:
|
||||||
pip = module.get_bin_path(p, False, ['%s/bin' % env])
|
candidate_pip_basenames.insert(0, executable)
|
||||||
# pip should have been found by now. The final call to get_bin_path
|
if pip is None:
|
||||||
# will trigger fail_json.
|
if env is None:
|
||||||
if not pip:
|
opt_dirs = []
|
||||||
pip = module.get_bin_path('pip', True, ['%s/bin' % env])
|
else:
|
||||||
else:
|
# Try pip with the virtualenv directory first.
|
||||||
# Explicit pip executable.
|
opt_dirs = ['%s/bin' % env]
|
||||||
pip = module.get_bin_path(executable, True)
|
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
|
return pip
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue