[Python-checkins] cpython (3.2): Issue #12618: py_compile cannot create files in current directory

meador.inge python-checkins at python.org
Mon Nov 28 16:39:17 CET 2011


http://hg.python.org/cpython/rev/661fb211f220
changeset:   73773:661fb211f220
branch:      3.2
parent:      73768:bceb6aea8554
user:        Meador Inge <meadori at gmail.com>
date:        Mon Nov 28 09:27:32 2011 -0600
summary:
  Issue #12618: py_compile cannot create files in current directory

Initial patch by Sjoerd de Vries.

files:
  Lib/py_compile.py           |  4 +++-
  Lib/test/test_py_compile.py |  9 +++++++++
  Misc/ACKS                   |  1 +
  Misc/NEWS                   |  3 +++
  4 files changed, 16 insertions(+), 1 deletions(-)


diff --git a/Lib/py_compile.py b/Lib/py_compile.py
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -130,7 +130,9 @@
         else:
             cfile = imp.cache_from_source(file)
     try:
-        os.makedirs(os.path.dirname(cfile))
+        dirname = os.path.dirname(cfile)
+        if dirname:
+            os.makedirs(dirname)
     except OSError as error:
         if error.errno != errno.EEXIST:
             raise
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -39,6 +39,15 @@
         py_compile.compile(self.source_path)
         self.assertTrue(os.path.exists(self.cache_path))
 
+    def test_cwd(self):
+        cwd = os.getcwd()
+        os.chdir(self.directory)
+        py_compile.compile(os.path.basename(self.source_path),
+                           os.path.basename(self.pyc_path))
+        os.chdir(cwd)
+        self.assertTrue(os.path.exists(self.pyc_path))
+        self.assertFalse(os.path.exists(self.cache_path))
+
     def test_relative_path(self):
         py_compile.compile(os.path.relpath(self.source_path),
                            os.path.relpath(self.pyc_path))
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -941,6 +941,7 @@
 Kurt Vile
 Norman Vine
 Frank Visser
+Sjoerd de Vries
 Niki W. Waibel
 Wojtek Walczak
 Charles Waldman
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@
 Library
 -------
 
+- Issue #12618: Fix a bug that prevented py_compile from creating byte
+  compiled files in the current directory.  Initial patch by Sjoerd de Vries.
+
 - Issue #13444: When stdout has been closed explicitly, we should not attempt
   to flush it at shutdown and print an error.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list