summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-09-20 10:30:49 -0700
committerToshio Kuratomi <a.badger@gmail.com>2016-09-20 10:47:33 -0700
commit24921cfb9076f524f3685e4b74647b3eea64ecbd (patch)
tree4e011be407280c4338a124afbe1313938cd3bf8c
parent16c9597ca7b6594568978a91f71aa86e8ec07ecf (diff)
downloadansible-modules-core-pip-freeze-and-pip-setuptools.tar.gz
pip list isn't available on pip less than 1.3 so make a fallbackpip-freeze-and-pip-setuptools
-rwxr-xr-xpackaging/language/pip.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/packaging/language/pip.py b/packaging/language/pip.py
index df41251b..b5d00284 100755
--- a/packaging/language/pip.py
+++ b/packaging/language/pip.py
@@ -438,8 +438,30 @@ def main():
changed = False
if name:
- # Pip spits an upgrade notice to stdout that we have to get rid of
pkg_list = [p for p in out.split('\n') if not p.startswith('You are using') and not p.startswith('You should consider') and p]
+ if pkg_cmd.endswith(' freeze') and ('pip' in name or 'setuptools' in name):
+ # Older versions of pip (pre-1.3) do not have pip list.
+ # pip freeze does not list setuptools or pip in its output
+ # So we need to get those via a specialcase
+ if 'setuptools' in name:
+ try:
+ import setuptools
+ except ImportError:
+ # Could not import, assume that it is not installed
+ pass
+ else:
+ pkg_list.append('setuptools==%s' % setuptools.__version__)
+
+ if 'pip' in name:
+ try:
+ import pkg_resources
+ except ImportError:
+ # Could not import pkg_resources. pip requires
+ # pkg_resources so assume that it is not installed
+ pass
+ else:
+ pkg_list.append('pip==%s' % pkg_resources.get_distribution('pip').version)
+
for pkg in name:
is_present = _is_present(pkg, version, pkg_list, pkg_cmd)
if (state == 'present' and not is_present) or (state == 'absent' and is_present):