diff options
author | Donald Stufft <donald@stufft.io> | 2016-10-30 15:17:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-30 15:17:10 -0400 |
commit | 765d52e6bd33271382663111f19d235b83320363 (patch) | |
tree | 6808f11c379163de5cfe1195899e259f4287d3b3 | |
parent | f21cd1190f669939fb09407a57d3a1e347945a98 (diff) | |
download | pip-765d52e6bd33271382663111f19d235b83320363.tar.gz |
Let the search service handle search order (#4044)
-rw-r--r-- | pip/commands/search.py | 19 | ||||
-rw-r--r-- | tests/functional/test_search.py | 40 |
2 files changed, 4 insertions, 55 deletions
diff --git a/pip/commands/search.py b/pip/commands/search.py index ed5eed788..bd2ea8ad3 100644 --- a/pip/commands/search.py +++ b/pip/commands/search.py @@ -5,6 +5,7 @@ import sys import textwrap from pip.basecommand import Command, SUCCESS +from pip.compat import OrderedDict from pip.download import PipXmlrpcTransport from pip.models import PyPI from pip.utils import get_terminal_size @@ -68,21 +69,17 @@ def transform_hits(hits): packages with the list of versions stored inline. This converts the list from pypi into one we can use. """ - packages = {} + packages = OrderedDict() for hit in hits: name = hit['name'] summary = hit['summary'] version = hit['version'] - score = hit['_pypi_ordering'] - if score is None: - score = 0 if name not in packages.keys(): packages[name] = { 'name': name, 'summary': summary, 'versions': [version], - 'score': score, } else: packages[name]['versions'].append(version) @@ -90,16 +87,8 @@ def transform_hits(hits): # if this is the highest version, replace summary and score if version == highest_version(packages[name]['versions']): packages[name]['summary'] = summary - packages[name]['score'] = score - - # each record has a unique name now, so we will convert the dict into a - # list sorted by score - package_list = sorted( - packages.values(), - key=lambda x: x['score'], - reverse=True, - ) - return package_list + + return list(packages.values()) def print_results(hits, name_column_width=None, terminal_width=None): diff --git a/tests/functional/test_search.py b/tests/functional/test_search.py index b376cf617..35b937f0f 100644 --- a/tests/functional/test_search.py +++ b/tests/functional/test_search.py @@ -28,13 +28,11 @@ def test_pypi_xml_transformation(): """ pypi_hits = [ { - '_pypi_ordering': 100, 'name': 'foo', 'summary': 'foo summary', 'version': '1.0', }, { - '_pypi_ordering': 200, 'name': 'foo', 'summary': 'foo summary v2', 'version': '2.0', @@ -48,49 +46,11 @@ def test_pypi_xml_transformation(): ] expected = [ { - 'score': 200, 'versions': ['1.0', '2.0'], 'name': 'foo', 'summary': 'foo summary v2', }, { - 'score': 50, - 'versions': ['1.0'], - 'name': 'bar', - 'summary': 'bar summary', - }, - ] - assert transform_hits(pypi_hits) == expected - - -def test_invalid_pypi_transformation(): - """ - Test transformation of pypi when ordering None - """ - pypi_hits = [ - { - '_pypi_ordering': None, - 'name': 'bar', - 'summary': 'bar summary', - 'version': '1.0', - }, - { - '_pypi_ordering': 100, - 'name': 'foo', - 'summary': 'foo summary', - 'version': '1.0', - }, - ] - - expected = [ - { - 'score': 100, - 'versions': ['1.0'], - 'name': 'foo', - 'summary': 'foo summary', - }, - { - 'score': 0, 'versions': ['1.0'], 'name': 'bar', 'summary': 'bar summary', |