From 106fb10dabd60994f74d5ce6ab43c2e7c19d9ee8 Mon Sep 17 00:00:00 2001 From: Blair Zajac Date: Tue, 29 Jan 2013 09:30:09 -0800 Subject: [PATCH] library/pip: add support for virtualenv's --system-site-packages. --- library/pip | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/pip b/library/pip index db86a58b2fe..289072c6047 100644 --- a/library/pip +++ b/library/pip @@ -47,6 +47,15 @@ options: - An optional path to a I(virtualenv) directory to install into required: false default: null + virtualenv_site_packages: + description: + - Whether the virtual environment will inherit packages from the + global site-packages directory. Note that if this setting is + changed on an already existing virtual environment it will not + have any effect, the environment must be deleted and newly + created. + required: false + default: no use_mirrors: description: - Whether to use mirrors when installing python libraries. If using @@ -74,7 +83,9 @@ examples: - code: "pip: name=flask version=0.8" description: Install I(flask) python package on version 0.8. - code: "pip: name=flask virtualenv=/my_app/venv" - description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv)" + description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv), inheriting none of the globally installed modules" + - code: "pip: name=flask virtualenv=/my_app/venv virtualenv_site_packages=yes" + description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv), inheriting globally installed modules" - code: "pip: requirements=/my_app/requirements.txt" description: Install specified python requirements. - code: "pip: requirements=/my_app/requirements.txt virtualenv=/my_app/venv" @@ -137,6 +148,7 @@ def main(): version=dict(default=None, required=False), requirements=dict(default=None, required=False), virtualenv=dict(default=None, required=False), + virtualenv_site_packages=dict(default='no', choices=BOOLEANS), use_mirrors=dict(default='yes', choices=BOOLEANS), extra_args=dict(default=None, required=False), ), @@ -164,7 +176,10 @@ def main(): if env: virtualenv = module.get_bin_path('virtualenv', True) if not os.path.exists(os.path.join(env, 'bin', 'activate')): - cmd = '%s %s' % (virtualenv, env) + if module.boolean(module.params['virtualenv_site_packages']): + cmd = '%s --system-site-packages %s' % (virtualenv, env) + else: + cmd = '%s %s' % (virtualenv, env) rc, out_venv, err_venv = module.run_command(cmd) out += out_venv err += err_venv