Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r82324:e79f457ab18f
Date: 2016-02-19 10:37 +0100
http://bitbucket.org/pypy/pypy/changeset/e79f457ab18f/

Log:    import cffi/b4991ae7ce3a

diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -550,6 +550,7 @@
                 lst.append(value)
         #
         if '__pypy__' in sys.builtin_module_names:
+            import os
             if sys.platform == "win32":
                 # we need 'libpypy-c.lib'.  Current distributions of
                 # pypy (>= 4.1) contain it as 'libs/python27.lib'.
@@ -558,11 +559,15 @@
                     ensure('library_dirs', os.path.join(sys.prefix, 'libs'))
             else:
                 # we need 'libpypy-c.{so,dylib}', which should be by
-                # default located in 'sys.prefix/bin'
+                # default located in 'sys.prefix/bin' for installed
+                # systems.
                 pythonlib = "pypy-c"
                 if hasattr(sys, 'prefix'):
-                    import os
                     ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+            # On uninstalled pypy's, the libpypy-c is typically found in
+            # .../pypy/goal/.
+            if hasattr(sys, 'prefix'):
+                ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 
'goal'))
         else:
             if sys.platform == "win32":
                 template = "python%d%d"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
@@ -28,11 +28,14 @@
 
 def prefix_pythonpath():
     cffi_base = os.path.dirname(os.path.dirname(local_dir))
-    pythonpath = os.environ.get('PYTHONPATH', '').split(os.pathsep)
+    pythonpath = org_env.get('PYTHONPATH', '').split(os.pathsep)
     if cffi_base not in pythonpath:
         pythonpath.insert(0, cffi_base)
     return os.pathsep.join(pythonpath)
 
+def setup_module(mod):
+    mod.org_env = os.environ.copy()
+
 
 class EmbeddingTests:
     _compiled_modules = {}
@@ -46,14 +49,12 @@
     def get_path(self):
         return str(self._path.ensure(dir=1))
 
-    def _run_base(self, args, env_extra={}, **kwds):
-        print('RUNNING:', args, env_extra, kwds)
-        env = os.environ.copy()
-        env.update(env_extra)
-        return subprocess.Popen(args, env=env, **kwds)
+    def _run_base(self, args, **kwds):
+        print('RUNNING:', args, kwds)
+        return subprocess.Popen(args, **kwds)
 
-    def _run(self, args, env_extra={}):
-        popen = self._run_base(args, env_extra, cwd=self.get_path(),
+    def _run(self, args):
+        popen = self._run_base(args, cwd=self.get_path(),
                                  stdout=subprocess.PIPE,
                                  universal_newlines=True)
         output = popen.stdout.read()
@@ -65,6 +66,7 @@
         return output
 
     def prepare_module(self, name):
+        self.patch_environment()
         if name not in self._compiled_modules:
             path = self.get_path()
             filename = '%s.py' % name
@@ -74,9 +76,8 @@
             # find a solution to that: we could hack sys.path inside the
             # script run here, but we can't hack it in the same way in
             # execute().
-            env_extra = {'PYTHONPATH': prefix_pythonpath()}
-            output = self._run([sys.executable, os.path.join(local_dir, 
filename)],
-                               env_extra=env_extra)
+            output = self._run([sys.executable,
+                                os.path.join(local_dir, filename)])
             match = re.compile(r"\bFILENAME: (.+)").search(output)
             assert match
             dynamic_lib_name = match.group(1)
@@ -120,28 +121,35 @@
         finally:
             os.chdir(curdir)
 
+    def patch_environment(self):
+        path = self.get_path()
+        # for libpypy-c.dll or Python27.dll
+        path = os.path.split(sys.executable)[0] + os.path.pathsep + path
+        env_extra = {'PYTHONPATH': prefix_pythonpath()}
+        if sys.platform == 'win32':
+            envname = 'PATH'
+        else:
+            envname = 'LD_LIBRARY_PATH'
+        libpath = org_env.get(envname)
+        if libpath:
+            libpath = path + os.path.pathsep + libpath
+        else:
+            libpath = path
+        env_extra[envname] = libpath
+        for key, value in sorted(env_extra.items()):
+            if os.environ.get(key) != value:
+                print '* setting env var %r to %r' % (key, value)
+                os.environ[key] = value
+
     def execute(self, name):
         path = self.get_path()
-        env_extra = {'PYTHONPATH': prefix_pythonpath()}
-        if sys.platform == 'win32':
-            _path = os.environ.get('PATH')
-            # for libpypy-c.dll or Python27.dll
-            _path = os.path.split(sys.executable)[0] + ';' + _path
-            env_extra['PATH'] = _path
-        else:
-            libpath = os.environ.get('LD_LIBRARY_PATH')
-            if libpath:
-                libpath = path + ':' + libpath
-            else:
-                libpath = path
-            env_extra['LD_LIBRARY_PATH'] = libpath
         print('running %r in %r' % (name, path))
         executable_name = name
         if sys.platform == 'win32':
             executable_name = os.path.join(path, executable_name + '.exe')
         else:
             executable_name = os.path.join('.', executable_name)
-        popen = self._run_base([executable_name], env_extra, cwd=path,
+        popen = self._run_base([executable_name], cwd=path,
                                stdout=subprocess.PIPE,
                                universal_newlines=True)
         result = popen.stdout.read()
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to