2015-07-07 07:00:21 +00:00
|
|
|
"""Helpers to install PyPi packages."""
|
2015-08-30 01:11:24 +00:00
|
|
|
import os
|
2015-07-07 07:00:21 +00:00
|
|
|
import subprocess
|
2015-07-16 01:37:24 +00:00
|
|
|
import sys
|
2015-07-07 07:00:21 +00:00
|
|
|
|
|
|
|
|
2015-08-30 01:11:24 +00:00
|
|
|
def install_package(package, upgrade=False, target=None):
|
2015-07-07 07:00:21 +00:00
|
|
|
"""Install a package on PyPi. Accepts pip compatible package strings.
|
|
|
|
Return boolean if install successfull."""
|
|
|
|
# Not using 'import pip; pip.main([])' because it breaks the logger
|
2015-08-30 03:17:47 +00:00
|
|
|
args = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
|
2015-07-07 07:00:21 +00:00
|
|
|
if upgrade:
|
|
|
|
args.append('--upgrade')
|
2015-08-30 01:11:24 +00:00
|
|
|
if target:
|
|
|
|
args += ['--target', os.path.abspath(target)]
|
2015-07-16 01:37:24 +00:00
|
|
|
try:
|
|
|
|
return 0 == subprocess.call(args)
|
|
|
|
except subprocess.SubprocessError:
|
|
|
|
return False
|