fixes case where name is omitted from pip arg list

This code:
```
    if name.endswith('.tar.gz') or name.endswith('.tar.bz2') or
name.endswith('.zip'):
        is_tar = True
```
was not checking whether name is defined since it is an
optional param.
This commit is contained in:
John Jarvis 2013-05-18 20:59:21 -04:00
parent 423fe82d94
commit daf4c358f7

View file

@ -20,6 +20,7 @@
# #
import tempfile import tempfile
import os
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -184,22 +185,6 @@ def main():
if state == 'latest' and version is not None: if state == 'latest' and version is not None:
module.fail_json(msg='version is incompatible with state=latest') module.fail_json(msg='version is incompatible with state=latest')
# pip can accept a path to a local project or a VCS url beginning
# with svn+, git+, hg+, or bz+ and these sources usually do not qualify
# --use-mirrors. Furthermore, the -e option is applied only when
# source is a VCS url. Therefore, we will have branch cases for each
# type of sources.
#
# is_vcs includes those begin with svn+, git+, hg+ or bzr+
# is_tar ends with .zip, .tar.gz, or .tar.bz2
is_vcs = False
is_tar = False
if name.endswith('.tar.gz') or name.endswith('.tar.bz2') or name.endswith('.zip'):
is_tar = True
elif name.startswith('svn+') or name.startswith('git+') or \
name.startswith('hg+') or name.startswith('bzr+'):
is_vcs = True
err = '' err = ''
out = '' out = ''
@ -226,23 +211,37 @@ def main():
cmd = '%s %s' % (pip, state_map[state]) cmd = '%s %s' % (pip, state_map[state])
# If is_vcs=True, we must add -e option (we assume users won't add that to extra_args).
if is_vcs:
args_list = [] # used if extra_args is not used at all
if extra_args:
args_list = extra_args.split(' ')
if '-e' not in args_list:
args_list.append('-e')
# Ok, we will reconstruct the option string
extra_args = ' '.join(args_list)
# for tarball or vcs source, applying --use-mirrors doesn't really make sense
is_package = is_vcs or is_tar # just a shortcut for bool
if not is_package and state != 'absent' and use_mirrors:
cmd += ' --use-mirrors'
if extra_args: if extra_args:
cmd += ' %s' % extra_args cmd += ' %s' % extra_args
if name: if name:
# pip can accept a path to a local project or a VCS url beginning
# with svn+, git+, hg+, or bz+ and these sources usually do not qualify
# --use-mirrors. Furthermore, the -e option is applied only when
# source is a VCS url. Therefore, we will have branch cases for each
# type of sources.
#
# is_vcs includes those begin with svn+, git+, hg+ or bzr+
# is_tar ends with .zip, .tar.gz, or .tar.bz2
is_vcs = False
is_tar = False
if name.endswith('.tar.gz') or name.endswith('.tar.bz2') or name.endswith('.zip'):
is_tar = True
elif name.startswith('svn+') or name.startswith('git+') or \
name.startswith('hg+') or name.startswith('bzr+'):
is_vcs = True
# If is_vcs=True, we must add -e option (we assume users won't add that to extra_args).
if is_vcs:
args_list = [] # used if extra_args is not used at all
if extra_args:
args_list = extra_args.split(' ')
if '-e' not in args_list:
args_list.append('-e')
# Ok, we will reconstruct the option string
extra_args = ' '.join(args_list)
# for tarball or vcs source, applying --use-mirrors doesn't really make sense
is_package = is_vcs or is_tar # just a shortcut for bool
if not is_package and state != 'absent' and use_mirrors:
cmd += ' --use-mirrors'
cmd += ' %s' % _get_full_name(name, version) cmd += ' %s' % _get_full_name(name, version)
elif requirements: elif requirements:
cmd += ' -r %s' % requirements cmd += ' -r %s' % requirements