From b4c14421f7c2f25aa1839e15d75aa004cf420e67 Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Wed, 17 Nov 2010 00:26:57 -0800
Subject: [PATCH] =?utf8?q?bundled=20zetuptoolz:=20prefer=20locally-availab?=
 =?utf8?q?le=20distributions=20over=20remotely-downloaded=20distributions?=
 =?utf8?q?=20above=20all=20This=20fixes=20#1233.=20Actually=20the=20previo?=
 =?utf8?q?us=20patches=E2=80=94[20101103034740-93fa1-9df33552497282eb72a84?=
 =?utf8?q?e5b434d035974bf2dbb]=20and=20[20101117080828-92b7f-dc0239f30b26e?=
 =?utf8?q?7e5d40b228114fb399c1e190ec5]=E2=80=94fixed=20it,=20but=20with=20?=
 =?utf8?q?them=20zetuptoolz=20would=20download=20a=20higher-numbered=20dis?=
 =?utf8?q?tribution=20from=20the=20net=20instead=20of=20using=20the=20loca?=
 =?utf8?q?lly-available=20(fake)=20pycryptopp-0.5.24,=20thus=20preventing?=
 =?utf8?q?=20the=20tests=20from=20passing.=20This=20patch=20changes=20that?=
 =?utf8?q?=20behavior=20(which=20is=20an=20improvement=20in=20its=20own=20?=
 =?utf8?q?right)=20and=20also=20fixes=20a=20bug=20in=20the=20tests.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 .../setuptools/package_index.py               | 43 +++++++++++++------
 src/buildtest/test_build_with_fake_dist.py    |  2 +-
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/setuptools-0.6c16dev2.egg/setuptools/package_index.py b/setuptools-0.6c16dev2.egg/setuptools/package_index.py
index 1cfdccc5..3d82d933 100644
--- a/setuptools-0.6c16dev2.egg/setuptools/package_index.py
+++ b/setuptools-0.6c16dev2.egg/setuptools/package_index.py
@@ -19,6 +19,21 @@ PYPI_MD5 = re.compile(
 URL_SCHEME = re.compile('([-+.a-z0-9]{2,}):',re.I).match
 EXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz".split()
 
+def is_local(url_or_fname):
+    """ Return True if url_or_fname is a "file:" url or if it is a schemaless thing (which is presumably a filename). """
+    mo = URL_SCHEME(url_or_fname)
+    return not (mo and mo.group(1).lower()!='file')
+
+def url_or_fname_to_fname(url_or_fname):
+    """ Assert that is_local(url_or_fname) then if it is a "file:" url, parse it and run url2pathname on it, else just return it. """
+    assert is_local(url_or_fname)
+
+    mo = URL_SCHEME(url_or_fname)
+    if mo:
+        return urllib2.url2pathname(urlparse.urlparse(url)[2])
+    else:
+        return url_or_fname
+
 __all__ = [
     'PackageIndex', 'distros_for_url', 'parse_bdist_wininst',
     'interpret_distro_name',
@@ -436,18 +451,22 @@ class PackageIndex(Environment):
         def find(env, req):
             # Find a matching distribution; may be called more than once
 
-            # first try to find a platform-dependent dist
-            for allow_platform_independent in (False, True):
-                for dist in env[req.key]:
-                    if dist.precedence==DEVELOP_DIST and not develop_ok:
-                        if dist not in skipped:
-                            self.warn("Skipping development or system egg: %s",dist)
-                            skipped[dist] = 1
-                        continue
-
-                    if (dist in req and (allow_platform_independent or dist.platform is not None) and
-                        (dist.precedence<=SOURCE_DIST or not source)):
-                        return dist
+            # first try to find a local dist
+            for allow_remote in (False, True):
+                # then try to find a platform-dependent dist
+                for allow_platform_independent in (False, True):
+                    for dist in env[req.key]:
+                        if dist.precedence==DEVELOP_DIST and not develop_ok:
+                            if dist not in skipped:
+                                self.warn("Skipping development or system egg: %s",dist)
+                                skipped[dist] = 1
+                            continue
+
+                        if ((is_local(dist.location) or allow_remote) and
+                            (dist in req) and
+                            ((allow_platform_independent or dist.platform is not None) and
+                             (dist.precedence<=SOURCE_DIST or not source))):
+                            return dist
 
         if force_scan:
             self.prescan()
diff --git a/src/buildtest/test_build_with_fake_dist.py b/src/buildtest/test_build_with_fake_dist.py
index 57a4b533..ec6abe3a 100644
--- a/src/buildtest/test_build_with_fake_dist.py
+++ b/src/buildtest/test_build_with_fake_dist.py
@@ -7,4 +7,4 @@ class T(unittest.TestCase):
         import pycryptopp
         if pycryptopp.__version__ != '0.5.24':
             raise unittest.SkipTest("We can't tell if this worked because this system has a different version of pycryptopp already installed. See comment in misc/build_helpers/test-with-fake-dists.py for details.")
-        self.succeed()
+        # If you tried to build 9.9.99 then you would have gotten an exception and stopped before you even ran this test, so I guess you succeeded!
-- 
2.45.2