Author: Antonio Cuni <[email protected]>
Branch: app_main-refactor
Changeset: r55572:b2ecd50779e1
Date: 2012-06-11 13:33 +0200
http://bitbucket.org/pypy/pypy/changeset/b2ecd50779e1/

Log:    kill resolvedirof from app_main, and instead use the one which is
        already in sys (exposed via sys.pypy_resolvedirof)

diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -46,6 +46,7 @@
         'pypy_getudir'          : 'state.pypy_getudir',    # not translated
         'pypy_find_stdlib'      : 'initpath.pypy_find_stdlib',
         'pypy_find_executable'  : 'initpath.pypy_find_executable',
+        'pypy_resolvedirof'     : 'initpath.pypy_resolvedirof',
 
         '_getframe'             : 'vm._getframe', 
         '_current_frames'       : 'currentframes._current_frames', 
diff --git a/pypy/module/sys/initpath.py b/pypy/module/sys/initpath.py
--- a/pypy/module/sys/initpath.py
+++ b/pypy/module/sys/initpath.py
@@ -138,6 +138,10 @@
 def pypy_find_executable(space, executable):
     return space.wrap(find_executable(executable))
 
+@unwrap_spec(filename='str0')
+def pypy_resolvedirof(space, filename):
+    return space.wrap(resolvedirof(filename))
+
 @unwrap_spec(executable='str0')
 def pypy_find_stdlib(space, executable):
     path, prefix = find_stdlib(get_state(space), executable)
diff --git a/pypy/module/sys/test/test_initpath.py 
b/pypy/module/sys/test/test_initpath.py
--- a/pypy/module/sys/test/test_initpath.py
+++ b/pypy/module/sys/test/test_initpath.py
@@ -1,6 +1,7 @@
 import py
 import os.path
-from pypy.module.sys.initpath import compute_stdlib_path, find_executable, 
find_stdlib
+from pypy.module.sys.initpath import (compute_stdlib_path, find_executable, 
find_stdlib,
+                                      resolvedirof)
 from pypy.module.sys.version import PYPY_VERSION, CPYTHON_VERSION
 
 def build_hierarchy(prefix):
@@ -82,3 +83,13 @@
     monkeypatch.setenv('PATH', str(a))
     a.join('pypy.exe').ensure(file=True)
     assert find_executable('pypy') == a.join('pypy.exe')
+
+def test_resolvedirof(tmpdir):
+    foo = tmpdir.join('foo').ensure(dir=True)
+    bar = tmpdir.join('bar').ensure(dir=True)
+    myfile = foo.join('myfile').ensure(file=True)
+    assert resolvedirof(str(myfile)) == foo
+    if hasattr(myfile, 'mksymlinkto'):
+        myfile2 = bar.join('myfile')
+        myfile2.mksymlinkto(myfile)
+        assert resolvedirof(str(myfile2)) == foo
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -219,7 +219,6 @@
 
 if 'nt' in sys.builtin_module_names:
     IS_WINDOWS = True
-    DRIVE_LETTER_SEP = ':'
 else:
     IS_WINDOWS = False
 
@@ -585,7 +584,7 @@
             # on the command-line.
             filename = sys.argv[0]
             mainmodule.__file__ = filename
-            sys.path.insert(0, resolvedirof(filename))
+            sys.path.insert(0, sys.pypy_resolvedirof(filename))
             # assume it's a pyc file only if its name says so.
             # CPython goes to great lengths to detect other cases
             # of pyc file format, but I think it's ok not to care.
@@ -630,22 +629,6 @@
 
     return status
 
-def resolvedirof(filename):
-    import os
-    try:
-        filename = os.path.abspath(filename)
-    except OSError:
-        pass
-    dirname = os.path.dirname(filename)
-    if os.path.islink(filename):
-        try:
-            link = os.readlink(filename)
-        except OSError:
-            pass
-        else:
-            return resolvedirof(os.path.join(dirname, link))
-    return dirname
-
 def print_banner():
     print 'Python %s on %s' % (sys.version, sys.platform)
     print ('Type "help", "copyright", "credits" or '
@@ -724,6 +707,10 @@
         # fails)
         return path
 
+    def pypy_resolvedirof(s):
+        from pypy.module.sys.initpath import resolvedirof
+        return resolvedirof(s)
+
     # add an emulator for these pypy-only or 2.7-only functions
     # (for test_pyc_commandline_argument)
     import imp, runpy
@@ -765,6 +752,7 @@
 
     sys.pypy_find_executable = pypy_find_executable
     sys.pypy_find_stdlib = pypy_find_stdlib
+    sys.pypy_resolvedirof = pypy_resolvedirof
     sys.cpython_path = sys.path[:]
     try:
         sys.exit(int(entry_point(sys.argv[0], sys.argv[1:])))
diff --git a/pypy/translator/goal/test2/test_app_main.py 
b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -834,6 +834,9 @@
         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))
+        #
+        foo_py = prefix.join('foo.py').write("pass")
+        self.w_foo_py = self.space.wrap(str(foo_py))
 
     def test_setup_bootstrap_path(self):
         import sys
@@ -882,7 +885,7 @@
         try:
             import app_main
             pypy_c = os.path.join(self.trunkdir, 'pypy', 'translator', 'goal', 
'pypy-c')
-            app_main.entry_point(pypy_c, ['-c', 'pass'])
+            app_main.entry_point(pypy_c, [self.foo_py])
             # assert it did not crash
         finally:
             sys.path[:] = old_sys_path
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to