[pypy-svn] r75493 - in pypy/branch/sys-prefix/pypy: module/sys module/sys/test translator/goal translator/goal/test2
antocuni at codespeak.net
antocuni at codespeak.net
Tue Jun 22 15:14:27 CEST 2010
Author: antocuni
Date: Tue Jun 22 15:14:25 2010
New Revision: 75493
Added:
pypy/branch/sys-prefix/pypy/module/sys/test/test_initialpath.py (contents, props changed)
Modified:
pypy/branch/sys-prefix/pypy/module/sys/state.py
pypy/branch/sys-prefix/pypy/translator/goal/app_main.py
pypy/branch/sys-prefix/pypy/translator/goal/test2/test_app_main.py
Log:
improve the logic to search the library path: now lib_pypy and lib-python can
be found either on one of the parent directories of pypy-c, or in lib/pypy1.2/.
This allows multiple schemes of installation, such as:
- /usr/bin/pypy-c, /usr/lib/pypy1.2/
- /opt/pypy/pypy-c, /opt/pypy/{lib_pypy, lib_python}
- /opt/pypy/bin/pypy-c, /opt/pypy/{lib_pypy, lib_python}
Moreover it has not been tested on windows, but it should allow to install
pypy like this:
- c:\pypy\pypy-c.exe, c:\pypy\{lib_pypy, lib-python}
Modified: pypy/branch/sys-prefix/pypy/module/sys/state.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/module/sys/state.py (original)
+++ pypy/branch/sys-prefix/pypy/module/sys/state.py Tue Jun 22 15:14:25 2010
@@ -32,24 +32,30 @@
if not stat.S_ISDIR(st[0]):
raise OSError(errno.ENOTDIR, path)
-def getinitialpath(srcdir):
- # build the initial path from the srcdir, which is the path of
- # the "dist" directory of a PyPy checkout.
- from pypy.module.sys.version import CPYTHON_VERSION, PYPY_VERSION
- libdir = os.path.join(srcdir, 'lib')
+def getinitialpath(prefix):
+ from pypy.module.sys.version import PYPY_VERSION
+ libdir = os.path.join(prefix, 'lib')
pypyxy_dir = os.path.join(libdir, 'pypy%d.%d' % PYPY_VERSION[:2])
+ # search for the stdlib both in $PREFIX/lib/pypy1.2 and $PREFIX
+ for lib_prefix in (pypyxy_dir, prefix):
+ try:
+ return get_importlist(lib_prefix)
+ except OSError:
+ pass
+ raise OSError # stdlib not foud
+def get_importlist(lib_prefix):
+ from pypy.module.sys.version import CPYTHON_VERSION
dirname = '%d.%d.%d' % (CPYTHON_VERSION[0],
CPYTHON_VERSION[1],
CPYTHON_VERSION[2])
- lib_python = os.path.join(pypyxy_dir, 'lib-python')
-
+ lib_python = os.path.join(lib_prefix, 'lib-python')
python_std_lib = os.path.join(lib_python, dirname)
checkdir(python_std_lib)
python_std_lib_modified = os.path.join(lib_python, 'modified-' + dirname)
checkdir(python_std_lib_modified)
- lib_pypy = os.path.join(pypyxy_dir, 'lib_pypy')
+ lib_pypy = os.path.join(lib_prefix, 'lib_pypy')
checkdir(lib_pypy)
importlist = []
Added: pypy/branch/sys-prefix/pypy/module/sys/test/test_initialpath.py
==============================================================================
--- (empty file)
+++ pypy/branch/sys-prefix/pypy/module/sys/test/test_initialpath.py Tue Jun 22 15:14:25 2010
@@ -0,0 +1,32 @@
+import py
+from pypy.module.sys.state import getinitialpath
+from pypy.module.sys.version import PYPY_VERSION, CPYTHON_VERSION
+
+def build_hierarchy(prefix):
+ dirname = '%d.%d.%d' % (CPYTHON_VERSION[0],
+ CPYTHON_VERSION[1],
+ CPYTHON_VERSION[2])
+ a = prefix.join('lib_pypy').ensure(dir=1)
+ b = prefix.join('lib-python', 'modified-%s' % dirname).ensure(dir=1)
+ c = prefix.join('lib-python', dirname).ensure(dir=1)
+ return a, b, c
+
+
+def test_stdlib_in_pypyxy(tmpdir):
+ pypyxy = tmpdir.join('lib', 'pypy%d.%d' % PYPY_VERSION[:2])
+ dirs = build_hierarchy(pypyxy)
+ path = getinitialpath(str(tmpdir))
+ assert path == map(str, dirs)
+
+
+def test_stdlib_in_prefix(tmpdir):
+ dirs = build_hierarchy(tmpdir)
+ path = getinitialpath(str(tmpdir))
+ assert path == map(str, dirs)
+
+def test_stdlib_precedence(tmpdir):
+ pypyxy = tmpdir.join('lib', 'pypy%d.%d' % PYPY_VERSION[:2])
+ dirs1 = build_hierarchy(tmpdir)
+ dirs2 = build_hierarchy(pypyxy)
+ path = getinitialpath(str(tmpdir))
+ assert path == map(str, dirs2)
Modified: pypy/branch/sys-prefix/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/translator/goal/app_main.py (original)
+++ pypy/branch/sys-prefix/pypy/translator/goal/app_main.py Tue Jun 22 15:14:25 2010
@@ -183,9 +183,6 @@
return argv[i], i
def get_library_path(executable):
- AUTOSUBPATH = 'share' + os.sep + 'pypy-%d.%d'
- # set up a sys.path that depends on the local machine
- autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2]
search = executable
while 1:
dirname = resolvedirof(search)
@@ -197,10 +194,8 @@
break
newpath = sys.pypy_initial_path(dirname)
if newpath is None:
- newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath))
- if newpath is None:
- search = dirname # walk to the parent directory
- continue
+ search = dirname # walk to the parent directory
+ continue
break # found!
return newpath
Modified: pypy/branch/sys-prefix/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/translator/goal/test2/test_app_main.py (original)
+++ pypy/branch/sys-prefix/pypy/translator/goal/test2/test_app_main.py Tue Jun 22 15:14:25 2010
@@ -486,6 +486,7 @@
self.w_goal_dir = self.space.wrap(goal_dir)
self.w_fake_exe = self.space.wrap(str(fake_exe))
self.w_expected_path = self.space.wrap(expected_path)
+ self.w_trunkdir = self.space.wrap(os.path.dirname(autopath.pypydir))
def test_get_library_path(self):
import sys
@@ -500,3 +501,18 @@
assert newpath == self.expected_path
finally:
sys.path.pop()
+
+ def test_trunk_can_be_prefix(self):
+ import sys
+ import os
+ sys.path.append(self.goal_dir)
+ try:
+ import app_main
+ app_main.os = os
+ pypy_c = os.path.join(self.trunkdir, 'pypy', 'translator', 'goal', 'pypy-c')
+ newpath = app_main.get_library_path(pypy_c)
+ assert len(newpath) == 3
+ for p in newpath:
+ assert p.startswith(self.trunkdir)
+ finally:
+ sys.path.pop()
More information about the Pypy-commit
mailing list