Bug 920353 - Use PYCOMMANDPATH paths as site packages in pymake. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Sep 2013 16:43:53 +0900
changeset 354 6410fa823a2253f7d4c0b377d61d982fcd35f047
parent 353 5d83a8746631e1fa86f3f440c306909ca69b6e26
child 355 3ef1b1059c5c0e286ec77c28c72bc075cba10311
push id225
push usermh@glandium.org
push dateThu, 26 Sep 2013 07:49:34 +0000
reviewersgps
bugs920353
Bug 920353 - Use PYCOMMANDPATH paths as site packages in pymake. r=gps
pymake/process.py
--- a/pymake/process.py
+++ b/pymake/process.py
@@ -1,16 +1,17 @@
 """
 Skipping shell invocations is good, when possible. This wrapper around subprocess does dirty work of
 parsing command lines into argv and making sure that no shell magic is being used.
 """
 
 #TODO: ship pyprocessing?
 import multiprocessing
 import subprocess, shlex, re, logging, sys, traceback, os, imp, glob
+import site
 from collections import deque
 # XXXkhuey Work around http://bugs.python.org/issue1731717
 subprocess._cleanup = lambda: None
 import command, util
 if sys.platform=='win32':
     import win32process
 
 _log = logging.getLogger('pymake.process')
@@ -342,38 +343,29 @@ class PythonException(Exception):
         self.message = message
         self.exitcode = exitcode
 
     def __str__(self):
         return self.message
 
 def load_module_recursive(module, path):
     """
-    Emulate the behavior of __import__, but allow
-    passing a custom path to search for modules.
+    Like __import__, but allow passing a custom path to search for modules.
     """
-    bits = module.split('.')
     oldsyspath = sys.path
-    for i, bit in enumerate(bits):
-        dotname = '.'.join(bits[:i+1])
-        try:
-          f, path, desc = imp.find_module(bit, path)
-          # Add the directory the module was found in to sys.path
-          if path != '':
-              abspath = os.path.abspath(path)
-              if not os.path.isdir(abspath):
-                  abspath = os.path.dirname(path)
-              sys.path = [abspath] + sys.path
-          m = imp.load_module(dotname, f, path, desc)
-          if f is None:
-              path = m.__path__
-        except ImportError:
-            return
-        finally:
-            sys.path = oldsyspath
+    sys.path = []
+    for p in path:
+        site.addsitedir(p)
+    sys.path.extend(oldsyspath)
+    try:
+        __import__(module)
+    except ImportError:
+        return
+    finally:
+        sys.path = oldsyspath
 
 class PythonJob(Job):
     """
     A job that calls a Python method.
     """
     def __init__(self, module, method, argv, env, cwd, pycommandpath=None):
         self.module = module
         self.method = method