[pypy-svn] pypy default: Let pypy import .pyw files on Windows

amauryfa commits-noreply at bitbucket.org
Thu Mar 31 11:55:38 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r43041:dedfebb34586
Date: 2011-03-31 11:53 +0200
http://bitbucket.org/pypy/pypy/changeset/dedfebb34586/

Log:	Let pypy import .pyw files on Windows

diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -6,6 +6,7 @@
 from pypy.tool.udir import udir
 from pypy.rlib import streamio
 from pypy.conftest import gettestobjspace
+import pytest
 import sys, os
 import tempfile, marshal
 
@@ -109,6 +110,14 @@
             p.join('lone.pyc').write(p.join('x.pyc').read(mode='rb'),
                                      mode='wb')
 
+    # create a .pyw file
+    p = setuppkg("windows", x = "x = 78")
+    try:
+        p.join('x.pyw').remove()
+    except py.error.ENOENT:
+        pass
+    p.join('x.py').rename(p.join('x.pyw'))
+
     return str(root)
 
 
@@ -333,6 +342,11 @@
         import compiled.x
         assert compiled.x == sys.modules.get('compiled.x')
 
+    @pytest.mark.skipif("sys.platform != 'win32'")
+    def test_pyw(self):
+        import windows.x
+        assert windows.x.__file__.endswith('x.pyw')
+
     def test_cannot_write_pyc(self):
         import sys, os
         p = os.path.join(sys.path[-1], 'readonly')

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
@@ -58,6 +58,12 @@
     if os.path.exists(pyfile) and case_ok(pyfile):
         return PY_SOURCE, ".py", "U"
 
+    # on Windows, also check for a .pyw file
+    if sys.platform == 'win32':
+        pyfile = filepart + ".pyw"
+        if os.path.exists(pyfile) and case_ok(pyfile):
+            return PY_SOURCE, ".pyw", "U"
+
     # The .py file does not exist.  By default on PyPy, lonepycfiles
     # is False: if a .py file does not exist, we don't even try to
     # look for a lone .pyc file.


More information about the Pypy-commit mailing list