Repository: pypa/pip

Issue:
KeyError: '_pypi_ordering' when using new Pypi warehouse site with 'pip search'
- Pip version: 8.1.2
- Python version: 2.7.6
- Operating System: Ubuntu 14.04
### Description:

As discussed in issue #3767 and in IRC channel #pypa-dev, the pip command should work against the new Pypi warehouse site when using the `--index` option with the URL `https://pypi.io/pypi`.

However I did not get it to work. See below.
### What I've run:

```
$ pip search --index https://pypi.io/pypi GitPython

Exception:
Traceback (most recent call last):
  File "/home/maiera/virtualenvs/pywbem27/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/maiera/virtualenvs/pywbem27/local/lib/python2.7/site-packages/pip/commands/search.py", line 44, in run
    hits = transform_hits(pypi_hits)
  File "/home/maiera/virtualenvs/pywbem27/local/lib/python2.7/site-packages/pip/commands/search.py", line 75, in transform_hits
    score = hit['_pypi_ordering']
KeyError: '_pypi_ordering'
```



Discussion:

Resolving patch:
diff --git a/pip/commands/search.py b/pip/commands/search.py
--- a/pip/commands/search.py
+++ b/pip/commands/search.py
@@ -5,6 +5,7 @@
 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):


Test patch:
diff --git a/tests/functional/test_search.py b/tests/functional/test_search.py
--- 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',