Sync charm-helpers

This commit is contained in:
Corey Bryant
2015-05-06 16:00:24 +00:00
parent 959450577a
commit 726784567a
2 changed files with 17 additions and 18 deletions

View File

@@ -540,7 +540,7 @@ def git_clone_and_install(projects_yaml, core_project, depth=1):
if 'directory' in projects.keys():
parent_dir = projects['directory']
pip_create_virtualenv(proxy=http_proxy)
pip_create_virtualenv()
for p in projects['repositories']:
repo = p['repository']
@@ -611,9 +611,9 @@ def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy,
juju_log('Installing git repo from dir: {}'.format(repo_dir))
if http_proxy:
pip_install(repo_dir, proxy=http_proxy)
pip_install(repo_dir, proxy=http_proxy, venv=True)
else:
pip_install(repo_dir)
pip_install(repo_dir, venv=True)
return repo_dir

View File

@@ -54,8 +54,12 @@ def pip_install_requirements(requirements, **options):
pip_execute(command)
def pip_install(package, fatal=False, upgrade=False, **options):
def pip_install(package, fatal=False, upgrade=False, venv=False, **options):
"""Install a python package"""
if venv:
venv_python = os.path.join(charm_dir(), 'venv/bin/pip')
command = [venv_python, "install"]
else:
command = ["install"]
available_options = ('proxy', 'src', 'log', 'index-url', )
@@ -72,6 +76,9 @@ def pip_install(package, fatal=False, upgrade=False, **options):
log("Installing {} package with options: {}".format(package,
command))
if venv:
subprocess.check_call(command)
else:
pip_execute(command)
@@ -99,15 +106,7 @@ def pip_list():
return pip_execute(["list"])
def pip_create_virtualenv(parent_dir=charm_dir(), proxy=None):
"""Create and activate an isolated Python environment (virtualenv)."""
if proxy:
pip_install('virtualenv', proxy=proxy)
else:
pip_install('virtualenv')
venv_dir = os.path.join(parent_dir, 'venv')
subprocess.check_call(['virtualenv', '--no-site-packages', venv_dir])
venv_activate = os.path.join(venv_dir, 'bin/activate')
subprocess.check_call(['.', venv_activate], shell=True)
def pip_create_virtualenv():
"""Create an isolated Python environment."""
apt_install('python-virtualenv')
subprocess.check_call(['virtualenv', os.path.join(charm_dir(), 'venv')])