summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-11-28 09:27:32 -0600
committerMeador Inge <meadori@gmail.com>2011-11-28 09:27:32 -0600
commit7270d62977de9a6c19be0946a255674466cefe51 (patch)
tree7c515167ba398b107f1d90b935b67d69546d4ab0
parentebf9b25e02def456b5f921814e3e1456d827f844 (diff)
downloadcpython-7270d62977de9a6c19be0946a255674466cefe51.tar.gz
Issue #12618: py_compile cannot create files in current directory
Initial patch by Sjoerd de Vries.
-rw-r--r--Lib/py_compile.py4
-rw-r--r--Lib/test/test_py_compile.py9
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 16 insertions, 1 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
index e0f98cb741..5adb70a293 100644
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -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
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
index 8ad0897433..f3c1a6a44b 100644
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -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))
diff --git a/Misc/ACKS b/Misc/ACKS
index 7f7296e0d0..5d75404149 100644
--- 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
diff --git a/Misc/NEWS b/Misc/NEWS
index eaadaafb03..3041a73f85 100644
--- 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.