summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-02-19 10:38:41 +0100
committerArmin Rigo <arigo@tunes.org>2016-02-19 10:38:41 +0100
commitd2b3a16f8a6a18f5d77faf45b1f60f39feb3cd68 (patch)
tree4ee68792074812ed5ff09085bbe17cccabe9f4e3
parent45875d24496406df79a0c713625b4a4041b108b0 (diff)
parent11e551048da4dd36c488646acb77431a269a496a (diff)
downloadcffi-d2b3a16f8a6a18f5d77faf45b1f60f39feb3cd68.tar.gz
merge heads
-rw-r--r--cffi/api.py9
-rw-r--r--testing/embedding/test_basic.py54
2 files changed, 38 insertions, 25 deletions
diff --git a/cffi/api.py b/cffi/api.py
index 70ef93a..289bac3 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -550,6 +550,7 @@ class FFI(object):
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 @@ class FFI(object):
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/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
index 142a416..ec5f22b 100644
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -27,11 +27,14 @@ def check_lib_python_found(tmpdir):
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 = {}
@@ -45,14 +48,12 @@ class EmbeddingTests:
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()
@@ -64,6 +65,7 @@ class EmbeddingTests:
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
@@ -73,9 +75,8 @@ class EmbeddingTests:
# 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)
@@ -119,28 +120,35 @@ class EmbeddingTests:
finally:
os.chdir(curdir)
- def execute(self, name):
+ 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':
- _path = os.environ.get('PATH')
- # for libpypy-c.dll or Python27.dll
- _path = os.path.split(sys.executable)[0] + ';' + _path
- env_extra['PATH'] = _path
+ envname = 'PATH'
else:
- libpath = os.environ.get('LD_LIBRARY_PATH')
- if libpath:
- libpath = path + ':' + libpath
- else:
- libpath = path
- env_extra['LD_LIBRARY_PATH'] = libpath
+ 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()
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()