Add "auto" method of installing pip
This commit is contained in:
parent
6cf17a054b
commit
6d8cf3adb6
|
@ -33,6 +33,8 @@ deploy = make_deploy(__file__)
|
|||
|
||||
|
||||
def bootstrap_python(c, pip_from_apt=True, pip_eager=True,
|
||||
pip_auto=False,
|
||||
pip_package_name=None,
|
||||
virtualenvwrapper_from_apt=False,
|
||||
upgrade_virtualenvwrapper=True,
|
||||
workon_home='/srv/envs', user='rattail',
|
||||
|
@ -52,7 +54,10 @@ def bootstrap_python(c, pip_from_apt=True, pip_eager=True,
|
|||
apt.install(c, 'python-dev')
|
||||
|
||||
# pip
|
||||
install_pip(c, use_apt=pip_from_apt, python3=python3, eager=pip_eager)
|
||||
install_pip(c, auto=pip_auto, python3=python3,
|
||||
use_apt=pip_from_apt,
|
||||
apt_package_name=pip_package_name,
|
||||
eager=pip_eager)
|
||||
|
||||
# virtualenvwrapper
|
||||
workon_home = workon_home.rstrip('/')
|
||||
|
@ -104,16 +109,34 @@ def install_python(c, version, globally=False, verbose=False):
|
|||
version, short_version))
|
||||
|
||||
|
||||
def install_pip(c, use_apt=False, python3=False, eager=True):
|
||||
def install_pip(c, auto=False, python3=False,
|
||||
use_apt=False, apt_package_name=None,
|
||||
eager=True):
|
||||
"""
|
||||
Install/upgrade the Pip installer for Python.
|
||||
"""
|
||||
if use_apt:
|
||||
if python3:
|
||||
apt.install(c, 'python3-pip')
|
||||
else:
|
||||
apt.install(c, 'python-pip')
|
||||
else:
|
||||
# first check for existing pip; we do nothing if already present
|
||||
pip_ = 'pip3' if python3 else 'pip2'
|
||||
if not c.sudo('which {}'.format(pip_), warn=True).failed:
|
||||
return
|
||||
|
||||
if auto: # try apt first, then fall back to get-pip.py
|
||||
package = apt_package_name
|
||||
if not package:
|
||||
package = 'python3-pip' if python3 else 'python-pip'
|
||||
result = apt.install(c, package, warn=True)
|
||||
if result.failed:
|
||||
c.sudo('wget -O get-pip.py https://bootstrap.pypa.io/get-pip.py')
|
||||
python = 'python3' if python3 else 'python2'
|
||||
c.sudo('{} get-pip.py'.format(python))
|
||||
c.sudo('rm get-pip.py')
|
||||
|
||||
elif use_apt: # use apt only, w/ no fallback
|
||||
if not apt_package_name:
|
||||
apt_package_name = 'python3-pip' if python3 else 'python-pip'
|
||||
apt.install(c, apt_package_name)
|
||||
|
||||
else: # *deprecated* method using easy_install
|
||||
apt.install(c, 'build-essential', 'python-dev', 'libssl-dev', 'libffi-dev')
|
||||
if c.run('which pip', warn=True).failed:
|
||||
apt.install(c, 'python-pkg-resources', 'python-setuptools')
|
||||
|
|
Loading…
Reference in a new issue