]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12618: py_compile cannot create files in current directory
authorMeador Inge <meadori@gmail.com>
Mon, 28 Nov 2011 15:27:32 +0000 (09:27 -0600)
committerMeador Inge <meadori@gmail.com>
Mon, 28 Nov 2011 15:27:32 +0000 (09:27 -0600)
Initial patch by Sjoerd de Vries.

Lib/py_compile.py
Lib/test/test_py_compile.py
Misc/ACKS
Misc/NEWS

index e0f98cb741d3f28c3705a32f41badb990a55c6f0..5adb70a2939fdd247d24f12ee3ba2fc492717506 100644 (file)
@@ -130,7 +130,9 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1):
         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
index 8ad0897433b7078ffbfc9f110c081ed0001d05c9..f3c1a6a44b68149c69ecaeb72e68b19a9ceae18e 100644 (file)
@@ -39,6 +39,15 @@ class PyCompileTests(unittest.TestCase):
         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))
index 7f7296e0d050489dd73c38b0ad35e1e62da61fc8..5d754041492b9d771b92a75ae13f0a000ac288ad 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -941,6 +941,7 @@ Kannan Vijayan
 Kurt Vile
 Norman Vine
 Frank Visser
+Sjoerd de Vries
 Niki W. Waibel
 Wojtek Walczak
 Charles Waldman
index eaadaafb03eabf4fdee848417dbbbb775b41d302..3041a73f85c643b7117821970f0b465eb1049e2e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Core and Builtins
 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.