Add a virtualenv_python argument to the pip module

This allows specifying the Python version to use when creating the
virtualenv. See issue #586.
reviewable/pr18780/r1
Wouter Bolsterlee 10 years ago
parent 19b49c1d96
commit 8ce0284ace

@ -70,6 +70,14 @@ options:
C(virtualenv2), C(~/bin/virtualenv), C(/usr/local/bin/virtualenv). C(virtualenv2), C(~/bin/virtualenv), C(/usr/local/bin/virtualenv).
required: false required: false
default: virtualenv default: virtualenv
virtualenv_python:
version_added: "FIXME"
description:
- The Python executable used for creating the virtual environment.
For example C(python3.4), C(python2.7). When not specified, the
system Python version is used.
required: false
default: null
state: state:
description: description:
- The state of module - The state of module
@ -224,6 +232,7 @@ def main():
virtualenv=dict(default=None, required=False), virtualenv=dict(default=None, required=False),
virtualenv_site_packages=dict(default='no', type='bool'), virtualenv_site_packages=dict(default='no', type='bool'),
virtualenv_command=dict(default='virtualenv', required=False), virtualenv_command=dict(default='virtualenv', required=False),
virtualenv_python=dict(default=None, required=False, type='str'),
use_mirrors=dict(default='yes', type='bool'), use_mirrors=dict(default='yes', type='bool'),
extra_args=dict(default=None, required=False), extra_args=dict(default=None, required=False),
chdir=dict(default=None, required=False), chdir=dict(default=None, required=False),
@ -239,6 +248,7 @@ def main():
version = module.params['version'] version = module.params['version']
requirements = module.params['requirements'] requirements = module.params['requirements']
extra_args = module.params['extra_args'] extra_args = module.params['extra_args']
virtualenv_python = module.params['virtualenv_python']
chdir = module.params['chdir'] chdir = module.params['chdir']
if state == 'latest' and version is not None: if state == 'latest' and version is not None:
@ -256,18 +266,21 @@ def main():
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=True)
virtualenv = os.path.expanduser(virtualenv_command) cmd = os.path.expanduser(virtualenv_command)
if os.path.basename(virtualenv) == virtualenv: if os.path.basename(cmd) == cmd:
virtualenv = module.get_bin_path(virtualenv_command, True) cmd = module.get_bin_path(virtualenv_command, True)
if module.params['virtualenv_site_packages']: if module.params['virtualenv_site_packages']:
cmd = '%s --system-site-packages %s' % (virtualenv, env) cmd += ' --system-site-packages'
else: else:
cmd_opts = _get_cmd_options(module, virtualenv) cmd_opts = _get_cmd_options(module, cmd)
if '--no-site-packages' in cmd_opts: if '--no-site-packages' in cmd_opts:
cmd = '%s --no-site-packages %s' % (virtualenv, env) cmd += ' --no-site-packages'
else:
cmd = '%s %s' % (virtualenv, env) if virtualenv_python:
cmd += ' -p%s' % virtualenv_python
cmd = "%s %s" % (cmd, env)
this_dir = tempfile.gettempdir() this_dir = tempfile.gettempdir()
if chdir: if chdir:
this_dir = os.path.join(this_dir, chdir) this_dir = os.path.join(this_dir, chdir)

Loading…
Cancel
Save