From 20127ffdf5aed7fd14c9de31c1a010b6fd6fa5c7 Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Wed, 28 Jan 2009 22:56:08 -0700
Subject: [PATCH] setup: always create a support dir and populate it with a
 site-packages and add same to the PYTHONPATH, just in case someone is going
 to do "build", "develop", or "test" or something else which triggers a build
 I think there must be a much better solution for this -- probably to fix
 setuptools #54 and ship our own fork of setuptools and rely on it.

---
 setup.py | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/setup.py b/setup.py
index 7f10422b..54f566f0 100644
--- a/setup.py
+++ b/setup.py
@@ -22,27 +22,14 @@ def pylibdir(prefixdir):
 basedir = os.path.dirname(os.path.abspath(__file__))
 supportlib = pylibdir(os.path.join(basedir, "support"))
 
-
+prefixdirs = [] # argh!  horrible kludge to work-around setuptools #54
 for i in range(len(sys.argv)):
     arg = sys.argv[i]
-    prefixdir = None
     if arg.startswith("--prefix="):
-        prefixdir = arg[len("--prefix="):]
+        prefixdirs.append(arg[len("--prefix="):])
     if arg == "--prefix":
         if len(sys.argv) > i+1:
-            prefixdir = sys.argv[i+1]
-
-    if prefixdir:
-        libdir = pylibdir(prefixdir)
-        try:
-            os.makedirs(libdir)
-        except EnvironmentError, le:
-            # Okay, maybe the dir was already there.
-            pass
-        sys.path.append(libdir)
-        pp = os.environ.get('PYTHONPATH','').split(os.pathsep)
-        pp.append(libdir)
-        os.environ['PYTHONPATH'] = os.pathsep.join(pp)
+            prefixdirs.append(sys.argv[i+1])
 
     if arg.startswith("develop") or arg.startswith("build") or arg.startswith("test"): # argh! horrible kludge to workaround setuptools #17
         if sys.platform == "linux2":
@@ -53,6 +40,21 @@ for i in range(len(sys.argv)):
             sd = "/System/Library/Frameworks/Python.framework/Versions/%d.%d/Extras/lib/python" % (sys.version_info[:2])
             sys.argv.extend(["--site-dirs", sd])
 
+if not prefixdirs:
+    prefixdirs.append("support")
+
+for prefixdir in prefixdirs:
+    libdir = pylibdir(prefixdir)
+    try:
+        os.makedirs(libdir)
+    except EnvironmentError, le:
+        # Okay, maybe the dir was already there.
+        pass
+    sys.path.append(libdir)
+    pp = os.environ.get('PYTHONPATH','').split(os.pathsep)
+    pp.append(libdir)
+    os.environ['PYTHONPATH'] = os.pathsep.join(pp)
+
 try:
     from ez_setup import use_setuptools
 except ImportError:
-- 
2.45.2