[pypy-commit] pypy default: cleanup os.path.isdir by registering a specialcase for windows (ronan)

mattip noreply at buildbot.pypy.org
Thu May 15 21:37:26 CEST 2014


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r71535:523cda68ea97
Date: 2014-05-15 22:37 +0300
http://bitbucket.org/pypy/pypy/changeset/523cda68ea97/

Log:	cleanup os.path.isdir by registering a specialcase for windows
	(ronan)

diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -2,7 +2,7 @@
 Implementation of the interpreter-level default import logic.
 """
 
-import sys, os, stat, genericpath
+import sys, os, stat
 
 from pypy.interpreter.module import Module
 from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -522,8 +522,7 @@
 
             path = space.str0_w(w_pathitem)
             filepart = os.path.join(path, partname)
-            # os.path.isdir on win32 is not rpython when pywin32 installed
-            if genericpath.isdir(filepart) and case_ok(filepart):
+            if os.path.isdir(filepart) and case_ok(filepart):
                 initfile = os.path.join(filepart, '__init__')
                 modtype, _, _ = find_modtype(space, initfile)
                 if modtype in (PY_SOURCE, PY_COMPILED):
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -65,6 +65,13 @@
     # (on CPython they are '==', but not identical either)
     return ctx.appcall(os.unlink, *args_w)
 
+if os.name == 'nt':
+    @register_flow_sc(os.path.isdir)
+    def sc_os_path_isdir(ctx, *args_w):
+        # Cpython win32 reroutes os.path.isdir to nt._isdir
+        # which is not rpython
+        import genericpath
+        return ctx.appcall(genericpath.isdir, *args_w)
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
 class StdOutBuffer:
diff --git a/rpython/translator/c/test/test_extfunc.py b/rpython/translator/c/test/test_extfunc.py
--- a/rpython/translator/c/test/test_extfunc.py
+++ b/rpython/translator/c/test/test_extfunc.py
@@ -1,5 +1,5 @@
 import py
-import os, time, sys, genericpath
+import os, time, sys
 from rpython.tool.udir import udir
 from rpython.rlib.rarithmetic import r_longlong
 from rpython.annotator import model as annmodel
@@ -243,8 +243,6 @@
     assert f() == False
 
 def test_os_path_isdir():
-    if sys.platform != 'win32':
-        py.test.skip('use generic.isdir() instead')
     directory = "./."
     def fn():
         return os.path.isdir(directory)
@@ -256,20 +254,6 @@
     f = compile(fn, [])
     assert f() == False
 
-def test_generic_isdir():
-    # os.path.isdir is not rpython once pywin is installed (win32 specific)
-    # genericpath.isdir is better.
-    directory = "./."
-    def fn():
-        return genericpath.isdir(directory)
-    f = compile(fn, [])
-    assert f() == True
-    directory = "some/random/name"
-    def fn():
-        return genericpath.isdir(directory)
-    f = compile(fn, [])
-    assert f() == False
-
 def test_time_time():
     import time
     def fn():


More information about the pypy-commit mailing list