Addresses #4735 Verify the virtualenv command supports --no-site-packages before passing it

This commit is contained in:
James Tanner 2013-11-05 18:51:41 -05:00
parent 9aa93fa307
commit 65d68bb1b4

View file

@ -144,6 +144,17 @@ EXAMPLES = '''
- pip: name=bottle executable=pip-3.3
'''
def _get_cmd_options(module, cmd):
thiscmd = cmd + " --help"
rc, stdout, stderr = module.run_command(thiscmd)
#import epdb; epdb.serve()
if rc != 0:
module.fail_json(msg="Could not get --help output from %s" % virtualenv)
words = stdout.strip().split()
cmd_options = [ x for x in words if x.startswith('--') ]
return cmd_options
def _get_full_name(name, version=None):
if version is None:
@ -247,7 +258,11 @@ def main():
if module.params['virtualenv_site_packages']:
cmd = '%s --system-site-packages %s' % (virtualenv, env)
else:
cmd = '%s --no-site-packages %s' % (virtualenv, env)
cmd_opts = _get_cmd_options(module, virtualenv)
if '--no-site-packages' in cmd_opts:
cmd = '%s --no-site-packages %s' % (virtualenv, env)
else:
cmd = '%s %s' % (virtualenv, env)
os.chdir(tempfile.gettempdir())
if chdir:
os.chdir(chdir)