pypa/pip — pull request #683 by qwcode (2012-09-23 22:29:00+00:00)
Title: fix PackageFinder version sorting 

PackageFinder version sorting has only coincidentally been working due to the ordering of the various version lists prior to the sorting.

In the case where there were `file_versions` (when using file:// find-links), they were always sorting before existing `found_versions` with the same version, when it was supposed to be in reverse.

The sort logic seemed to be originally intending to use the "Inf" object (in a multi-key sort) to cause existing installations to sort first when the version was the same, but wasn't actually using "Inf", and was only sorting by version alone.

You can recreate the problem by using these new tests (with the added simple-[23].0.tar.gz dists) against the old code.

tests.test_finder.test_finder_detects_latest_already_satisfied_find_links
tests.test_upgrade.test_upgrade_with_newest_already_installed

In these changes, I tried to implement what I think was originally intended, w/o doing too much refactor (better to isolate refactor in dedicated pulls). The result is that the coincidental success should now be real success for any type of version tuple.

This change also corrected a bug where a certain block of code was never running before due to an incorrect index reference. In that block, is the possibility of raising `BestVersionAlreadyInstalled` for non-upgrades, but the install code is not written to handle that (and moreover it looks like this block may never actually be executed given our use of package finder). I removed the raise for now, and it just returns None.