summaryrefslogtreecommitdiff
path: root/pip/commands/search.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2012-02-16 21:09:00 +0100
committerJannis Leidel <jannis@leidel.info>2012-02-16 21:09:00 +0100
commitee554dd82b8bc6ed9a3cf989b353126580fcc082 (patch)
treeb0604f39ed465673316fe94ffa29046ed868aafc /pip/commands/search.py
parent47f1b2c2b2523469e6107cb2ef325eb61fa8fcf1 (diff)
parent40ac381fad2cc31f75014f02d3e8bf755d933abb (diff)
downloadpip-1.1.tar.gz
Merge branch 'release/1.1'1.1
Diffstat (limited to 'pip/commands/search.py')
-rw-r--r--pip/commands/search.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/pip/commands/search.py b/pip/commands/search.py
index 1a6bf9c52..9f287e594 100644
--- a/pip/commands/search.py
+++ b/pip/commands/search.py
@@ -2,10 +2,12 @@ import sys
import textwrap
import pkg_resources
import pip.download
-from pip.basecommand import Command
+from pip.basecommand import Command, SUCCESS
from pip.util import get_terminal_size
from pip.log import logger
from pip.backwardcompat import xmlrpclib, reduce, cmp
+from pip.exceptions import CommandError
+from pip.status_codes import NO_MATCHES_FOUND
from distutils.version import StrictVersion, LooseVersion
@@ -25,8 +27,7 @@ class SearchCommand(Command):
def run(self, options, args):
if not args:
- logger.warn('ERROR: Missing required argument (search query).')
- return
+ raise CommandError('Missing required argument (search query).')
query = args
index_url = options.index
@@ -38,6 +39,9 @@ class SearchCommand(Command):
terminal_width = get_terminal_size()[0]
print_results(hits, terminal_width=terminal_width)
+ if pypi_hits:
+ return SUCCESS
+ return NO_MATCHES_FOUND
def search(self, query, index_url):
pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport)
@@ -106,7 +110,14 @@ def compare_versions(version1, version2):
return cmp(StrictVersion(version1), StrictVersion(version2))
# in case of abnormal version number, fall back to LooseVersion
except ValueError:
+ pass
+ try:
return cmp(LooseVersion(version1), LooseVersion(version2))
+ except TypeError:
+ # certain LooseVersion comparions raise due to unorderable types,
+ # fallback to string comparison
+ return cmp([str(v) for v in LooseVersion(version1).version],
+ [str(v) for v in LooseVersion(version2).version])
def highest_version(versions):